简体   繁体   中英

How to get the parent window URL from Iframe?

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>

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

alert(document.referrer);

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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