我的网页中有 html、javascript 和 jquery,但是当我把它放在 iframe 中时,它不会影响带有 iframe 标签的页面。是否有任何 html 代码可以让 iframe 中的内容影响带有 iframe 的页面?
问问题
217 次
2 回答
1
You can use window.parent
to get the id of the parent window, then use that to make changes with Javascript:
window.parent.document.getElementById("someElement").innerHTML = "Some new content";
if you're using jQuery you can do this:
window.parent.$("#someSelector").someFunction();
...but you must have jQuery loaded in the parent window for this to work.
于 2013-07-03T00:30:42.037 回答
1
Yes, you can do it in JavaScript.
through the window.parent.SomeJsMethodDefinedInTheParent()
you can call arbitrary JS in the parent.
Just define a method in the parent page and call it
于 2013-07-03T00:31:18.723 回答