How to get the parent window URL from Iframe?

老子叫甜甜 提交于 2019-12-19 06:21:36

问题


I know it's a security issue. But is there any way in HTML5. Cause I seen the below code opens a window with the parents URL in tweet box

<iframe src="https://platform.twitter.com/widgets/tweet_button.html"
        style="border: 0; width:130px; height:20px;"></iframe>

回答1:


Try this inside the iframe. It will alert the parent window's location URL.

alert(document.referrer);



回答2:


Give this JavaScript a go

var referrer = document.referrer;
console.log(referrer);

Hopefully it works for your purpose. More info on document.referer here if you want to know more:

https://developer.mozilla.org/en-US/docs/Web/API/document.referrer



来源:https://stackoverflow.com/questions/22523158/how-to-get-the-parent-window-url-from-iframe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!