简体   繁体   English

找出iFrame的当前URL

[英]Find Out Current URL of iFrame

Is there anyway of finding out the current URL of an iframe? 无论如何,找出iframe的当前URL? If I have an alert message onload set to document.getElementByTagName("iframe")[0].contentWindow.location.href the on safari I receive the current url everytime the iframe page changes. 如果我将警告消息加载设置为document.getElementByTagName(“ iframe”)[0] .contentWindow.location.href,则每次iframe页面更改时,我都会收到当前网址。 Unfortunately this doesn't work on Chrome due to Javascript Same Origin Policy guidelines. 不幸的是,由于Javascript同源政策的指导,这在Chrome上不起作用。 Can anyone recommend an alternative approach so someone getting the current URL of the page in an iframe? 谁能推荐一种替代方法,以便有人在iframe中获取页面的当前URL?

There could be different approaches to jump over same origin policy: 跳过相同的原产地策略可能有不同的方法:

I would suggest postMessages https://developer.mozilla.org/en-US/docs/DOM/window.postMessage 我建议postMessages https://developer.mozilla.org/en-US/docs/DOM/window.postMessage

should work with Firefox 3.5, Opera 10, Safari 4.0/Chrome 3.0+, Internet Explorer 8.0. 应该可以与Firefox 3.5,Opera 10,Safari 4.0 / Chrome 3.0 +,Internet Explorer 8.0一起使用。 And yet, you have to have access to both domains. 但是,您必须有权访问两个域。

you may also try something like old school XhrIframeProxy or even somehow, Xdomain requests but I am not sure latter has good support yet 您也可以尝试使用老式XhrIframeProxy或什至以某种方式Xdomain requests但我不确定后者是否有良好的支持

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

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