开发者

Is it possible to inject JavaScript code in a page embedded by IFRAME tag?

开发者 https://www.devze.com 2023-03-09 01:26 出处:网络
There 开发者_JAVA技巧is a certain page (say, named \"TargetPage.html\" in which I inject the Javascript code below by means of a Firefox extension:

There 开发者_JAVA技巧is a certain page (say, named "TargetPage.html" in which I inject the Javascript code below by means of a Firefox extension:

<!-- TargetPage.html -->
unsafeWindow.document.getElementById("target-element").click();

I want to embed this page into another page (say, named "AnotherPage.php") by using the HTML tag "iframe". Like below:

<!-- AnotherPage.php -->
<iframe src="TargetPage.html"></iframe>

Now that I embedded it via "iframe", there is no way to inject any JavaScript code with a browser extension.

Is there any way of running this code in the embedded page?


Only if both pages are in the same domain.

Otherwise is considered cross-domain scripts, and it's a big no-no, for browsers to allow it.

However, there are ways to achieve such communication between domains.

0

精彩评论

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