开发者

Javascript's window.parent not working in Chrome Extension

开发者 https://www.devze.com 2023-03-25 08:19 出处:网络
I have a chrome extension. The extension page has iframe that loads server, that redirects to page A and extension inject javascript to page A. Why can\'t i use window.parent i开发者_StackOverflow中文

I have a chrome extension. The extension page has iframe that loads server, that redirects to page A and extension inject javascript to page A. Why can't i use window.parent i开发者_StackOverflow中文版n javascript injected to page A? It appears to be undefined. Javascript is a content_script and i have page A included in permissions. thanks for help!


I'm a bit confused by the wording of your question, so I'll try to answer a few general cases. I think B is probably most relevant here.

A. If you are opening page A in a browser tab, window.parent will not refer to the extension page (if that's what you are trying to access)

B. If you are trying to access a function on the extension page from the iFrame (if the iFrame is what is getting redirected to page A), for instance: window.parent.someFunction(){}, you can only use window.parent if that code is in the iFrame (I think page A in this case), because Chrome sandboxes injected code, meaning that you cannot access the variables and functions present in the page code with the injected code, but you can still manipulate the DOM of the page. This may be why window.parent appears undefined to your injected code.

0

精彩评论

暂无评论...
验证码 换一张
取 消