0

有没有办法找出 iframe 的当前 URL?如果我将警报消息 onload 设置为 document.getElementByTagName("iframe")[0].contentWindow.location.href ,那么每次 iframe 页面更改时,我都会收到当前 url。不幸的是,由于 Javascript 同源政策指南,这在 Chrome 上不起作用。谁能推荐一种替代方法,以便有人在 iframe 中获取页面的当前 URL?

4

1 回答 1

0

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

should work with 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

于 2012-11-26T20:26:10.660 回答