2

Using HTML and Javascript, is it possible to create a link to a web page that automatically runs a specific Javascript function on the web page (e. g., a bookmarklet)? I have a bookmarklet that highlights all matches of a regular expression, and I want to create a hyperlink to http://en.wikipedia.org that automatically runs the bookmarklet on http://en.wikipedia.org.

Anderson Green
  • 25,996
  • 59
  • 164
  • 297
  • This appears to be relevant: http://stackoverflow.com/questions/52646/best-practice-legitimate-cross-site-scripting?rq=1 – Anderson Green Nov 08 '12 at 17:57
  • I do believe that is possible, can you provide us the source of your highlighting bookmarklet? As in, you can create a bookmarklet that can modify a page and add hyperlinks. – tomdemuyt Nov 08 '12 at 18:15
  • @tomdemuyt I got the bookmarklet from this site: https://www.squarefree.com/bookmarklets/pagedata.html – Anderson Green Nov 08 '12 at 19:23

2 Answers2

1

This is pretty much the textbook definition of cross site scripting, so no, generally that is not something you can do. The user must run the bookmarklet. What you can look into is making an addon or extension for browsers.

Asad Saeeduddin
  • 43,250
  • 5
  • 81
  • 127
  • @tomdemuyt Is it really possible to add a bookmarklet to an external site's hyperlink (so that the bookmarklet is executed when the page loads?) – Anderson Green Nov 08 '12 at 19:24
  • Ah, no. It must be a bookrmarklet stored as a bookmark that is clicked by the user. – tomdemuyt Nov 08 '12 at 22:30
1

You could use something like GreaseMonkey or something equivalent for the browser your on.

thatmiddleway
  • 3,584
  • 6
  • 31
  • 47