开发者

Javascript with iframe?

I have two iframe in single page now first iframe is URL is outside from host e.g www.google.com and second in local means contact.html now both having same JavaScript function e.g hello function() now which will first call ?开发者_Go百科


Neither will be called unless you call them. So it depends on when you call them.

If the call is inline in the page, then the one in the outer page will probably be called first, simply because it gets a head start.

Since they exist in different documents, neither will overwrite the other. Since the documents are on different hosts, neither can be overwritten from the other document.


1) only the code from same domain will be executed by other page from same domain
2) any function with the same name in another domain will have to be executed by a script from that domain

It will for sure not be the SAME function that is executed and if the function is blocking (like an alert) it will be a matter of which page loads first


I believe neither. You have to actually reference the iframe if you want to call a function in it:

document.getElementById('iframeid').contentWindow.myFunc();

Bare in mind you WILL NOT be able to access anything in an iframe unless it's of the same origin as the parent.


depends.

For instance

<script type='text/javascript'>
  hello();
</script>
<iframe src='www.google.com'></iframe>

You page's hello function is definitely called first.

<iframe src='www.google.com'></iframe>
  .... more stuff
<script type='text/javascript'>
  hello();
</script>

In this case, you can't predict since the iframe content is loaded asynchronously and might or might not fire before your page's hello call. If you are planning however to access the values returned these function across the iframe, you might run into browser security restrictions. In any case, post some code.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜