在保存小书签(favelet)之前停止 safari 评估 document.location
我创建了一个非常简单的小书签,用于将当前正在查看的网站的 URL 提交给脚本:
javascript:document.location%20=%20'http://www.example.com/script?user=___&key=___&url='+document.location
我将其作为 HTML 页面上的链接提供,用户可以将其拖动到他或她的书签工具栏或其他位置。 问题是 Safari 似乎会在创建书签之前单独评估 JS,因此提交的 URL 始终是我显示链接的页面的 URL。
我该如何解决这个问题,阻止 Safari 在添加书签之前评估 document.location,而不破坏其他浏览器的功能? 我宁愿避免为 Safari 提供单独的书签。
谢谢!
马拉
I have created a very simple bookmarklet to submit the url of the site currently being viewed to a script:
javascript:document.location%20=%20'http://www.example.com/script?user=___&key=___&url='+document.location
I serve this as a link on an HTML page that a user can drag up into his or her bookmarks toolbar or wherever. The catch is that Safari alone seems to evaluate the JS before creating the bookmark, so the URL submitted is always that of the page on which I display the link.
How do I go about fixing this, stopping Safari from evaluating the document.location before bookmarking, without breaking it for other browsers? I'd rather avoid having to have a separate bookmarklet for Safari.
Thanks!
Mala
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信答案是简单地用 escape() 包围评估的部分:
目前无法访问 mac/safari,所以我不能确定它是否有效......
I -believe- the answer is to simply surround the evaluated part with escape():
Don't currently have access to a mac/safari, so I can't tell you for sure if it works...