Search code examples
jqueryinternet-explorerfirefoxgoogle-chromebookmarks

How to bookmark JS injection link/code programatically and flash the bookmark afterward


I have this bookmarklet

javascript:%28function%28%29%7Bvar%20a%3Ddocument.createElement%28%22script%22%29%3Ba.type%3D%22text%2Fjavascript%22%3Ba.src%3D%22http://www.foo.com/bar.js.php%3F%22%2BMath.random%28%29%3Bdocument.getElementsByTagName%28%22head%22%29%5B0%5D.appendChild%28a%29%7D%29%28%29%3B

On my home page I will create a button or a link. When I click it, I want the above-mentioned bookmarklet to be bookmarked on user's browser if not exist with a label "Foomark".

If success, I want that bookmark to be flashed 3 times.

And I need callback functions registered to both success and failed event. (or it's even better to detect the browser beforehand whether it is programatically bookmark-able).

Solutions for all major browsers appreciated.

jQuery available.


Solution

  • Currently no browser allows JavaScript running on a page to create a bookmark. What you want is not possible.

    As an alternative, you could create extensions for Chrome and Firefox using mostly JavaScript/JSON. Unfortunately Internet Explorer doesn't have restartless extensions.