简体   繁体   English

从父窗口获取iframe html或名称

[英]Get iframe html or name from parent window

I have a page that loads few iframe's within itself. 我有一个页面,该页面在其内部加载了几个iframe。 Each iframe can invoke parent function. 每个iframe均可调用父函数。 For example like this: 例如这样:

$(document).ready(function() {
  parent.test();
}

I want to be able to find which iframe invoked test function. 我希望能够找到哪个iframe调用了测试功能。 I've tried to play with calleer.called properties but the best I could get is the function that calling test(). 我尝试使用calleer.Called属性,但最好的方法是调用test()的函数。 In my case it was $(document).ready function. 就我而言,它是$(document).ready函数。 Is there a way to get the name of iframe (or it's html name) which calling the function? 有没有一种方法可以获取调用该函数的iframe名称(或它的html名称)?

If you pass a parameter to the test function it will work: 如果将参数传递给测试函数,它将起作用:

$(document).ready(function() {
  parent.test('name of this iframe');
}

OR even better 甚至更好

$(document).ready(function() {
  parent.test(window.name);
}

Then you just need to use that value passed to the inside of the test function. 然后,您只需要使用传递给测试函数内部的值即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM