【发布时间】:2014-04-25 12:50:29
【问题描述】:
我正在尝试使用 window.open() 和 $(document).ready(function() { ... }); 动态创建一个新窗口;我让它在 Chrome 和 Internet Explorer 上工作,但火狐没有触发 jQuery 代码。见以下代码:
index.html 代码:
<html>
<head>
</head>
<body>
<a href="javascript:void(0);" onclick = "showDetails('name', 'name2');">Link</a>
<script type="text/javascript">
function showDetails(name, timeStamp)
{
var w = window.open("", timeStamp);
var s = w.document.createElement("script");
s.type = "text/javascript";
s.src = "var eventArray = [];";
w.document.body.appendChild(s);
var s = w.document.createElement("script");
s.type = "text/javascript";
s.src = "http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js";
w.document.body.appendChild(s);
var s = w.document.createElement("script");
s.type = "text/javascript";
s.src = "test.js";
w.document.body.appendChild(s);
w.document.title = name;
w.document.close();
return false;
}
</script>
</body>
test.js 代码:
alert("executing js file");
$(document).ready( function()
{
alert("document ready fired");
});
第一个警报“正在执行 js 文件”正在执行,但不是第二个警报“文档准备触发”。
知道如何在 Firefox 上完成这项工作吗?
注意:
- w.document.close();并返回假;在this post 之后添加但仍然无法正常工作...
- jquery 加载正常
非常感谢您
【问题讨论】:
-
fiddle here.. jsfiddle.net/86KPD 两个警报都出现了。火狐28!
-
确保您已正确加载 jquery。并在控制台中检查诸如“$ 未定义”之类的错误
-
你是否包含了 jQuery?
-
大家好,jquery 加载正常,提琴手工作,但它没有打开一个新窗口,这是我的问题的目的。
-
您似乎在打开窗口后尝试操作 DOM 属性。如果那是,事实上,你正在尝试做的,它不会工作。您不能对另一个文档进行操作。
标签: javascript jquery html firefox window.open