Bookmarklet window.open 被大多数浏览器阻止,delicious/tumbler's 则不会
嘿伙计们—— 我正在开发的网站需要一个可从书签工具栏启动的书签。 我注意到某些浏览器阻止了我的书签。
然而,类似的小书签,例如 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)+
'¬es='+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 参数。 那么我假设,如果是这种情况,从书签加载的实际页面上的初始化脚本会以某种方式处理此异常?
有没有人有过这个问题的经验?您能给我指出任何资源或提示吗?我已经被这个障碍困住了一段时间了。
提前致谢
Hey guys --
The website I'm working on requires a bookmarklet launchable from your bookmark toolbar.
I've noticed that some browsers are blocking my bookmarklet.
However, similar bookmarklets such as Tumblr's, Twitter's, and Delicious' have workarounds where their bookmarklet pages are not getting blocked.
My current launch script looks like:
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));
It's a simple window.open, which is clearly not enough to handle certain exceptions
The sites, below is Delicious' launch script, all seem to have workarounds that look very similar to that of below:
javascript:(function(){
f='http://www.delicious.com/save
?url='+encodeURIComponent(window.location.href)+
'&title='+encodeURIComponent(document.title)+
'¬es='+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()}})()
It seems like they append some extra GET parameters to the URL if the user agent is firefox.
I'm assuming then, if that is the case, that the init scripts on the actual page loading from the bookmarklet handles this exception somehow?
Has anyone had any experience with this issue? Would you be able to point me to any resources or tips? I have been stuck with this roadblock for sometime now.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
美味的书签不会直接调用 window.open() - 它会创建一个函数(其中称为
a
),然后在setTimeout(a,0)
中执行该函数对于 Firefox(我假设您遇到的问题是在 Firefox 中)。您可以尝试类似的方法,看看它是否适合您。
the delicious bookmark does not directly invoke the window.open() - it creates a function (called
a
in there) which is then executed in asetTimeout(a,0)
for firefox (i assume the problem you have is in firefox).You can try a similar method, and see if it works for you.