Question

I have a JavaScript bookmarklet that when you open it, runs a script that is a mailto which puts a timestamp in the body. QR codes will open up my mailto links perfectly, but I need this to have a timestamp in it, so I use this:

javascript:location.href='mailto:example@gmail.com?SUBJECT=Data&BODY=Time:'+(new%20Date().getTime())

It runs on my iPhone or iPad as a bookmark, but I want to make a QR code to open the JavaScript inside Safari instead of opening a URL.

The problem is with QR code generators, they all automatically put http:// at the beginning of URLs, which throws the script off. I can send it as plain text, but I can’t get that to open in Safari.

Any ideas on how this could be done? I had a couple thoughts:

  • anyone know of a smart enough QR reader app that would be able to run the script on its own?

  • anyone know of a dumb enough QR reader that it won’t put http:// in front of the link, but will still try to open it in Safari?

  • use a URL that automatically runs the script, but this won’t work without an internet connection, and it means users can just easily go back to the website

  • build my own app, but I have absolutely no idea how to do that

Thanks in advance.

Was it helpful?

Solution

I would use a normal url, which points to a web page where just that simple script runs. To enable offline capacibility just declare an HTML5 offline application manifest!

This way u only need internet the first time u use the QR code. It seems like u have a good control over the devices, so this shouldnt be a problem. At least less then a custom QR App!

For diffrent QR codes just use the hashtag # in the url and do the rest in the JS. So its always the same Web Page and it can be loaded offline!

OTHER TIPS

mailto: is a URI Scheme (Mailto URI Scheme), hence http:// should not be prepended by QR Code generators nor QR Code reader.

  • Use "plain text" in the generator if it adds http://. For a QR Code, URL and text format are the same, nothing is added to the raw data. Unitag QR Code generator will let you create a mailto: "URL QR Code".
  • QR Code readers also vary, some try to prepend http:// if they recognize some kind of URLs in the raw data

Your problem is javascript: no QR Code reader I know will execute it, and every mechanism I can think of won't work:

  • open the link directly (Javascript won't execute)
  • open the link trough a url-shortener (Javascript won't execute either)

What you need is a url-shortener that will "execute the Javascript" or in some other way, inject the date. This is possible with some rare url-shorteners, BeeTagg does that (http://www.beetagg.com/) but also Unitag (https://www.unitaglive.com, but that's in development).

Disclaimer: I work at Unitag.

It's easy to create a QR code which doesn't have http:// in front of it. In this case, I used my PHP QR Code Generator. Most decent one will work.

Here's the JavaScript in the QR code.

enter image description here

I couldn't find a single QR Scanner which would execute the code after scanning.

I think the best thing to do is...

  1. Point your QR code to a public facing web page.
  2. Put the JavaScript on the page.
  3. Get the JS to run once the page has loaded.
  4. The phone should automatically open its email client.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top