12

I was researching how to create bookmarklets for use with mobile safari and I ran across this problem:

I'm not sure why am unable to find any questions on this topic. And my Google searches came up with nothing as well. But it appears that iOS has completely disallowed JavaScript being entered into the address bar of mobile safari. There is a message that appears like this one:

Safari cannot run the script because JavaScript is not allowed to be used this way

They've even gone so far as to ensure that when you're editing a bookmark on mobile Safari, There is no way to escape Single quotes or double quotes and they have completely disabled double-quotes from the keyboard - thus handicapping the user's ability to create a bookmark with those characters in it.

So is there any way to make a bookmarklet that actually does anything? For instance, Can I create a bookmarklet that'll allow me to link to a particular website using the selected text as a parameter into the url?

And it just me or is this something new?

JayGee
  • 577
  • 6
  • 16

1 Answers1

13

The solution to bookmarklets in mobile Safari is to just not use the address bar. Create a bookmark for some random site, and edit it afterwards. I.e.:

  1. Visit google.com or some other random site
  2. Bookmark it (using the share button)
  3. Go to your bookmarks and tap edit
  4. Select your placeholder bookmark and enter your code in the address field
  5. Save the changes

That's it. A little awkward, but it works.

danlei
  • 14,121
  • 5
  • 58
  • 82
  • 1
    Hurray! it works! the answer doesn't make it completely clear though: you need to add a bookmark with your JavaScript code as the URL and a label, *BUT*, as opposed to other browsers (Firefox/Chrome) where you can type the label into the address bar and select your entry from the suggest menu, on Safari you must instead open the bookmarks menu and single tap the bookmark (NOT in edit mode). – ccpizza Mar 17 '18 at 12:27
  • @ccpizza Chrome doesn't run bookmarklets from the bookmarks menu anyway, which is superior. – Melab Apr 15 '19 at 01:16
  • @Melab: chrome for ios (v 10.3.3) runs bookmarklets both from the address bar, *and* from the bookmarks menu. To run from the address bar you need to type the _name_ of the bookmarklet and then tap the bookmark suggestion in the dropdown. To run from the Bookmarks menu tap the three dots > bookmarks > tap the boomark name. – ccpizza Apr 15 '19 at 14:53