How to get parent window url from iframe?

I know this is a security issue. But is there an HTML5 way. The reason I saw that the code below opens a window with the parents url on twitter

<iframe src="https://platform.twitter.com/widgets/tweet_button.html" style="border: 0; width:130px; height:20px;"></iframe> 
+7
javascript html5 sandbox
source share
2 answers

Try this inside an iframe. It will alert the URL of the location of the parent window.

 alert(document.referrer); 
+12
source share

Give this javascript go

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

Hope this works for your purpose. Read more about document.referer here if you want to know more:

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

+2
source share

All Articles