无法使用javascript找到新窗口的href
Unable to find href of new window using javascript
我正在使用下面提到的脚本来获取新打开的窗口的href,但它不起作用
浏览器ff7, ie9, win7
谁能让我知道什么是错误的脚本
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>
您无法获得与您正在运行的脚本在不同域或协议中的站点的URL。这是由于跨域限制。Chrome给你以下错误:不安全的JavaScript试图从URL为http://fiddle.jshell.net/_display/的框架访问URL为http://www.thesun.co.uk/sol/homepage/的框架。域、协议和端口必须匹配
我认为这可能是因为变量尚未设置。我认为你可能需要一个回调来说明dom已经为新窗口准备好了
相关文章:
- 窗口位置href更改不会重新加载
- window.location.href窗口未在javascript中定义
- 会话丢失窗口.位置.href.
- 如何检查窗口是否已滚动到href,然后在javascript/jQuery中执行函数
- 将文本框数据传递到JavaScript窗口.location.href
- 模式窗口中的 href
- 无法使用 window.location.href 更改为不同的窗口
- 来自 HREF 的新窗口/选项卡
- 如何从外部窗口对象获取 location.href
- 打开一个没有JavaScript或href的新窗口
- 将 href 加载到 iframe,但以父窗口为目标
- 在弹出窗口,背景页面,Chrome扩展程序中访问w.location.href
- 对窗口进行编码时遇到问题.位置.href.
- 在同一弹出窗口中打开 href 链接
- 在 chrome 中模拟 href 以打开新选项卡,而不是窗口.不使用点击
- 使用JavaScript获取href值并打开新窗口
- 在JSP中单击href时,关闭当前窗口并打开一个新窗口
- Javascript:在HTML弹出窗口中引用href位置
- 如何添加href"关闭“;链接到Fancybox模式窗口
- 从iframe发送POST请求,通知父窗口href