Execute javascript function in a another iframe when parent is from different domain - with jQuery?

倾然丶 夕夏残阳落幕 提交于 2019-12-12 22:13:54

问题


Yes , It's a similar question as in here , but mine is tagged with jquery.

in short : I have this scenario :

both documents (x.B.com and y.B.com) has document.domain="B.com";

But lets say Im in y.B.com and I want to execute work()

Running parent.frames['if1'].work(2); -- is working.

But I tried doing it with jQuery : (didn't succeed)

  • $('#if1', parent.document).contents().work(2);

  • $('#if1', parent.document)[0].work(2);

How can I do it ?


回答1:


If you can do it without jQuery, the amount of text you need to type is less without jQuery, and the code is easier to understanding without jQuery, then why use jQuery?

jQuery can't traverse a document from a different domain.

this was failed :

$('#if1', parent.document)...

while this was OK

parent.frames['if1']....



来源:https://stackoverflow.com/questions/16871003/execute-javascript-function-in-a-another-iframe-when-parent-is-from-different-do

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!