Adding favicon to javascript Bookmarklet (uses window.open)

后端 未结 3 452
醉酒成梦
醉酒成梦 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:29

    Some of the things that I've tried that might possibly get you going a bit more:

    Append a new link element to the current document:

    javascript: var newLink = document.createElement('link');
    newLink.setAttribute('rel','icon');
    newLink.setAttribute('type','image/png');
    newLink.setAttribute('href','http://www.tapper-ware.net/devel/js/JS.Bookmarklets/icons/next.png');
    document.querySelector('head').appendChild(newLink);
    void(0);
    

    Note that I was using the querySelector due to IE testing (though works in modern browsers as well). With Chrome and FF, I kept getting invalid character when trying to create the element, so I had to do piecewise attribute setting.

    Tried using base64 encoded image string using the "data:image/png;base64,iVBORw0KGgoAAAA..." URI schema, but that didn't help anything due to the fact that I still had to set it to the current HTML text (which I could do, but ran into the same problem as you above of no bookmarklet).

    Maybe this can't be done due to cross site scripting concerns? Not sure... Either way, really curious to see what you come up with (if you manage to come up with anything).

提交回复
热议问题