I am using below mentioned script to get href of new opened window, but its not working
Browser FF 7, IE 9, WIN 7
Can someone please let me know what’s wrong in the script
Thanks in Advance
Akhil
<html>
<head>
<script type="text/javascript">
function open_win()
{
var mywindow=window.open("http://thesun.co.uk");
var clbutton=document.createElement("button");
var par=document.getElementById("main");
clbutton.setAttribute("id","focus");
clbutton.setAttribute("value","CLICK");
clbutton.innerHTML="CLICK";
par.insertBefore(clbutton,null);
clbutton.onclick=function() {alertMsg(mywindow);}
}
function alertMsg(mywindow)
{
mywindow.focus();
var t=mywindow.location.href;
alert(t);
//mywindow.alert("testing");
mywindow.close();
}
</script>
</head>
<body onload="open_win()">
<p id="main"></p>
</body>
</html>
You can’t get the URL of sites that are in a different domain or protocol as the script that you are running. It is due to cross-domain restrictions. Chrome gives you the following error:
Unsafe JavaScript attempt to access frame with URL http://www.thesun.co.uk/sol/homepage/ from frame with URL http://fiddle.jshell.net/_display/. Domains, protocols and ports must match.