如何在 Firefox 中使用 JQuery 访问 parent.document 元素?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1133276/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 10:44:06  来源:igfitidea点击:

How to access parent.document elements using JQuery in firefox?

jqueryfirefox

提问by Ke.

For example:

例如:

$(elementid,top.document).attr(attributeName)

or

或者

$(elementid,parent.document).attr(attributeName)

works in IE or Chrome but doesn't work in Firefox.

适用于 IE 或 Chrome,但不适用于 Firefox。

Does anyone know what the firefox equivalence is?

有谁知道firefox等价物是什么?

Thanks!

谢谢!

回答by DLS

What about:

关于什么:

window.parent.$(elementid).attr(attributeName);

回答by Mahdi

Try this:

尝试这个:

$("#myid", top.document); 

or

或者

$("#myid", parent.document.body); 

Ref

参考

回答by Squiggs.

Try

尝试

$(elementid,window.parent.frames[0].document).attr(attributeName)

What are you trying to achieve - perhaps giving the question in context will get you better solutions.

你想达到什么目标——也许在上下文中提出问题会让你得到更好的解决方案。

回答by Mon

And don't forget document.domain = "yourdomain.com"before running $(selector, parent.document)because I ran into "access denied" issues just like location.hreffor iframes

并且document.domain = "yourdomain.com"在运行之前不要忘记,$(selector, parent.document)因为我遇到了“访问被拒绝”的问题,就像location.hrefiframe 一样