JavaScript 在操作浏览器和 DOM 方面是否有任何明显的限制?
我听说访问 Gmail 电子邮件的文本即使不是不可能(iframe)也是非常困难的。
是否有某些领域 JavaScript 无法执行某些操作?
I heard that getting access to the text a Gmail email is very difficult if not impossible (iframes).
Are there certain areas where JavaScript is not capable of doing something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
iframe 不会阻止您访问内容。 JavaScript 在操作 DOM 方面实际上没有任何限制……但是,它不能访问计算机上的内容,也不能用于上传文件等。它也无法读取闪存文件内的内容。无论如何,除了 JS 之外,你真的没有任何选择。你预计会遇到什么样的障碍?
iframes won't prevent you from accessing content. JavaScript doesn't really have any limits with regards to manipulating the DOM....it can't, however, access stuff on your computer, or be used to upload files and such. It can't read stuff inside flash files either. You don't really have any choices other than JS anyway.. what kind of road blocks are you anticipating?
由于您已选择使用 firefox-addon< /a> 标签:不,通过插件访问 Gmail 文本是没有问题的。但是,除非该网站托管在 mail.google.com 上,否则不可能从常规网站执行相同的操作。原因是一种名为同源策略的安全机制。网站通常受到同源策略的限制,而附加组件则不受限制。
Since you've chosen to use firefox-addon tag: no, getting access to Gmail text is unproblematic from an add-on. Doing the same from a regular website however isn't possible unless that website is hosted on mail.google.com. Reason is a security mechanism called same-origin policy. Websites are generally limited by the same-origin policy, add-ons are not.
不同的浏览器对 JavaScript 施加不同的限制,并为 JavaScript 提供不同的 API,以授予其访问不同形式数据的权限。直到最近,JavaScript 还无法访问本地文件;但是,现在某些浏览器中提供了 API 来执行此操作。
有一个称为“同源”策略的概念,用于确保从一个域或协议的上下文运行的 JavaScript 无法访问来自另一个域或协议的数据。然而,浏览器插件或扩展通常可以免除这些限制。另外,有些浏览器提供了专门用于不同源之间通信的API;但是,这些 API 通常要求在双方的合作和许可下完成此操作。
Different browsers have different limitations that they impose on JavaScript as well as different APIs that they provide to JavaScript to grant it access to different forms of data. Until recently, it was not possible for JavaScript to access local files; however, there are now APIs in some browsers to do this.
There is a concept known as the "same origin" policy that is used to ensure that JavaScript running from the context of one domain or protocol cannot access data from another domain or protocol. However, browser add-ons or extensions can often exempt themselves from these restrictions. Also, some browsers provide APIs specifically for communication between different origins; however, these APIs generally require that this is done with the cooperation and permission of both origins.
通过扩展 JS,您可以访问 Gmail 的任何部分。我编写了一个浏览器扩展程序,允许我将 Gmail 电子邮件转发给 Facebook 联系人。它还出现在 Facebook 中,允许我向 Gmail 联系人发送 Facebook 消息。这样我就不必担心将联系人从 Google 添加到 Facebook,反之亦然。
那个扩展很容易。一旦你通过了 iframe 部分,那就很简单了。祝你好运!
From extension JS, you can access any part of Gmail. I wrote a browser extension that allowed me to forward a Gmail email to a Facebook contact. It also appeared in Facebook and allowed me to send Facebook message to Gmail contact. It was so that I didn't need to worry about adding contacts from Google to Facebook and vice versa.
That extension was easy. Once you get passed the iframe piece, it is cake. Good luck!