我有以下代码打开并初始化新窗口:
var self = this;
self.editorWindow = window.open("about:blank", "Edit_image");
//self.editorWindow.onload = function () {
setTimeout(function () {
$("body", self.editorWindow.document).append($.tmpl('Editor',{ name : img.name, albumName : FPP.Aggregator.Data[img.serviceId][img.albumId].name })).addClass("edit-page");
var host = document.location.protocol + "//" + document.location.host;
// Load jQuery into new window
var head = self.editorWindow.document.getElementsByTagName('head')[0];
var script = self.editorWindow.document.createElement('script');
script.type = 'text/javascript';
script.src = host + '/JS/Res/jquery.min.js';
head.appendChild(script);
// Load jQuery-ui into new window
head = self.editorWindow.document.getElementsByTagName('head')[0];
script = self.editorWindow.document.createElement('script');
script.type = 'text/javascript';
script.src = host + '/JS/Res/jquery-ui.min.js';
head.appendChild(script);
// Load jQuery-ui css into new window
var link = self.editorWindow.document.createElement("link");
link.setAttribute("rel", "stylesheet");
link.setAttribute("type", "text/css");
link.setAttribute("href", host + "/Design/Default/css/ui-lightness/jquery-ui-1.8.15.custom.css");
head.appendChild(link);
// Load stylesheets
link = self.editorWindow.document.createElement("link");
link.setAttribute("rel", "stylesheet");
link.setAttribute("type", "text/css");
link.setAttribute("href", host + "/Design/720/style.css");
head.appendChild(link);
// other things ...
}, 400);
起初我这样做了:
var self = this;
self.editorWindow = window.open("about:blank", "Edit_image");
// Init stuff
但是这在FF中没有用(我正在开发的女巫),所以我做了这个
var self = this;
self.editorWindow = window.open("about:blank", "Edit_image");
self.editorWindow.onload = function () {
// Init stuff
}
但它在Chrome中无效,所以我想出了第一个代码示例。它在IE中不起作用。窗口已打开但未初始化。我不知道为什么,而且我没有想法。