javascript bookmarklet 与其他脚本隔离吗?
使用 DOM,我可以编写一个脚本来读取(并可能分配给变量)当前页面中其他脚本的代码,不是吗?
是否可以对小书签做同样的事情?也就是说,当前网页中的内联或外部脚本是否可以读取(并可能分配给变量)加载页面后执行的小书签的源代码,或者访问此类小书签的任何变量和/或属性?
Using DOM, I am able to write a script that read (and potentially assign to a variable) the code of the other scripts in the current page, isn't it?
Is it possible to do the same thing for bookmarklets? That is, could a inline or external script in the current web page read (and potentially assign to a variable) the source code of a bookmarklet that is executed after the loading of the page, or access any variable and/or property of such bookmarklet?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你尝试过看看会发生什么吗?看起来很容易制作一个测试页。答案是肯定的,它可以更改值,它不像代码在沙箱中运行。
Did you try it and see what happens? Seems easy to make a test page. Answer is yes it can change values, it is not like code runs in sandboxes.
为什么,不!它们根本不是,这就是小书签如此强大的原因。 Bookmarklet 只是在全局范围内执行的
javascript:
URL,并且可以完全控制当前window
让我们劫持 window.open() 方法,例如:
因此,以下弹出窗口位于我们的现在完全控制:
Why, no! They are not at all, thats why bookmarklets are so powerful. Bookmarklets are simply
javascript:
URLs executing in global scope and have full control on currentwindow
Lets hijack window.open() method for example:
So, the following popup is under our full control now: