开发者

Retrieve URL from iframe using window.postMessage

开发者 https://www.devze.com 2023-02-05 03:31 出处:网络
I\'m trying to access the URL of an iFrame that I open on my site.The iFrame is from another domain so traditional methods violate the same origin policy and are flagged as cross site scripting.Howeve

I'm trying to access the URL of an iFrame that I open on my site. The iFrame is from another domain so traditional methods violate the same origin policy and are flagged as cross site scripting. However, I just discovered window.postMessage, but I don't quite know how to pull it all together.

My goal is to capture the final URL in the iFrame. For example, a开发者_运维问答 user clicks a button on my site to open an iFrame. Say that iFrame loads a web site and the user clicks around on the site. When they close the iFrame, I want to capture the URL so the next time they click the button on my site, I can open the iFrame to the same state that the site was in last time they visited. Is this possible with window.postMessage?

Thanks!


document.iframe[name].src 
document.iframe[name].document.location.href
0

精彩评论

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