Search code examples
javascriptlocation-href

Can't retrieve window.location.href


I have the following code, trying to retrieve the url of the newly open window.

<script type="text/javascript">
this.windowRef = window.open("http://www.google.com");
console.log(this.windowRef.location.href);
</script>

However, when I look at the console of browser, the result shown is: "about:blank", instead of "www.google.com"

Why is that? How do I get www.google.com displayed?

Thanks for your help.


Solution

  • Same origin policy prevents you from reading data from other domains.