Adding favicon to javascript Bookmarklet (uses window.open)

后端 未结 3 524
醉酒成梦
醉酒成梦 2021-01-30 10:37

I have a bookmarklet that launches a window.open javascript function to open a small window with my bookmarklet -- an external feature used to communicate between any visted sit

3条回答
  •  逝去的感伤
    2021-01-30 11:31

    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 "javascript:" generated HTML page to load POP-ups, so you need to hit allow every time

    This is the code:

    Bookmarklet

    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. :)

提交回复
热议问题