Adding favicon to javascript Bookmarklet (uses window.open)

I tried and retried, and my first conclusion was: “It can’t be done (at least not in FF4 on Ubuntu 11.04)”. You need (I guess) a simple solution for your site visitors (drag&drop, add bookmark with 1 click …).

I have found a workaround, it does it’s job, but it is a little buggy (maybe someone can help fix it).
PROS:

  • add a icon to the bookmarklet
  • it uses windows.open
  • doesn’t leave empty pages behind

CONS:

  • it reloads the current page (instead of leave a page behind)
  • Can’t make Firefox POP-ul blocker allow “https://stackoverflow.com/questions/5952387/javascript:” generated HTML page to load POP-ups, so you need to hit allow every time

This is the code:

<a href="https://stackoverflow.com/questions/5952387/javascript:"&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;link rel=&quot;icon&quot; type=&quot;image/png&quot; href=&quot;http://www.tapper-ware.net/devel/js/JS.Bookmarklets/icons/next.png&quot; /&gt;&lt;/head&gt;&lt;body onLoad=&quot;window.open(\'http://example.com',\'test\',\'status=0,toolbar=0,location=0,menubar=0,resizable=false,scrollbars=false,height=379,width=379\');setTimeout(\'history.back(-1);\',100);&quot;&gt;&lt;/body&gt;&lt;/html&gt;';">Bookmarklet</a>

This is a link that you put on your page, the user needs to drag&drop this link to the bookmark bar (you can use something like Add Bookmark Script for adding it as a bookmark with 1 click), The bookmark has no icon until the user click’s it at least once.

So how it supose to work:
1. redirect the user to the generated HTML page from the bookmarklet (that makes the ICON posible)
2. onLoad open the window you need using “windows.open
3. redirect the page back using “history.back(-1)

In theory everithing happens so fast, that the user does’t see the new page, just that the current page is reloading, and a new windows appear.

The problem:
1. I use setTimeout for history.back beacause window.open is blocked by Firefox, so I need to click allow every single time (if somebody can fix this … we have a chance of using this, develop it further 🙂 )

I know THIS is not a reliable solution, but this is the only solution I’ve got so far.

Hope this helps a little. 🙂

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)