Bookmarklet window.open被大多数浏览器阻止,美味/不倒翁没有

时间:2011-04-28 00:38:06

标签: javascript popup bookmarklet

嘿伙计们 - 我正在处理的网站需要从书签工具栏中启动书签。 我注意到有些浏览器阻止了我的书签。

然而,类似的书签,如Tumblr,Twitter和Delicious'都有解决办法,因为它们的书签页面没有被阻止。

我当前的启动脚本如下:

javascript:void(window.open(%22http://mywebsite.com/share/form?
            u=%22+encodeURIComponent(location.href)+%22
            &t=%22+encodeURIComponent(document.title),
            %xz%22,%22status=0,toolbar=0,location=0,menubar=0,resizable=false,scrollbars=false,height=379,width=379%22));

这是一个简单的window.open,显然不足以处理某些异常

下面的网站是Delicious'启动脚本,似乎都有类似于下面的解决方法:

javascript:(function(){
f='http://www.delicious.com/save
?url='+encodeURIComponent(window.location.href)+
'&title='+encodeURIComponent(document.title)+
'&notes='+encodeURIComponent(''+(window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text))+
'&v=6&';
a=function(){
    if(!window.open(f
    +'noui=1&jump=doclose','deliciousuiv6','location=yes,links=no,scrollbars=no,toolbar=no,width=550,height=550'))
    location.href=f+'jump=yes'};
if(/Firefox/.test(navigator.userAgent))
    {setTimeout(a,0)}else{a()}})()

如果用户代理是firefox,它们似乎会向URL附加一些额外的GET参数。 我假设,如果是这样的话,从书签中加载的实际页面上的init脚本会以某种方式处理此异常?

有没有人有过这个问题的经验?你能指点我任何资源或提示吗?我一直坚持这个障碍。

提前致谢

1 个答案:

答案 0 :(得分:0)

美味书签不会直接调用window.open() - 它会创建一个函数(在那里称为a),然后在setTimeout(a,0)中为firefox执行(我假设你有问题)有在火狐)。

您可以尝试使用类似的方法,看看它是否适合您。