window.open无效的参数错误

问题描述:

所以,当我尝试运行这个脚本时,我总是收到一个无效的参数错误。错误发生在window.open(url, name, features);不幸的是我不知道如何解决这个问题。有任何想法吗?window.open无效的参数错误

共Utilities.js(其中问题的根源 - 4号线)

var wm = new function WindowManager() { 
    this.open = function (url, features) { 
     var name = this.getName(url); 
     var handle = window.open(url, name, features); 
     handle.focus(); 
     return handle; 
    }; 
    this.getName = function (url) { 
     name = getAbsolutePath(url); 
     return name.replace(/[:.\+\/\?\&\=\#\%\-]/g, "_").toLowerCase(); 
    }; 
    var getAbsolutePath = function (url) { 
     var a = document.createElement('a'); 
     a.href = url; 
     return a.href; 
    } 
}; 

openPopUp.js

function openPopup(url, width, height) 
{ 
    if (width == -1) width = 710; 
    if (height == -1) height = 500; 

    var left = (window.screen.availWidth - width)/2; 
    var top = (window.screen.availHeight - height)/2; 

    if (window.screenLeft>window.screen.availWidth) 
    { 
     left = left + window.screen.availWidth; 
    } 

    // open url in new browser window 
    var handle = wm.open(url, 'location=0, menubar=0, resizable=1, scrollbars=1, status=0, toolbar=0, width=' + width + 'px, height=' + height + 'px, top=' + top + 'px , left=' + left + 'px'); 

    //tile the windows so user can tell a new window has been opened 
    if (document.body.clientHeight==height) 
    { 
     var metricTop=10; 
     var metricLeft=10; 
     var thisTop=self.screenTop+metricTop; 
     var thisLeft=self.screenLeft+metricLeft; 
     if (thisTop<0) thisTop=0; 
     if (thisLeft<0) thisLeft=0; 
     handle.moveTo(thisLeft, thisTop); 
    } 

} 

function popOutOrIn(url, title, width, height, popOut) { 
    if (width == -1) width = 710; 
    if (height == -1) height = 500; 

    if (popOut === 'True') { 
     openPopup(url, width, height) 
    } 
    else { 
     window.top.popUpRadWindow(url, title, width, height); 
    } 
} 
+0

什么是错误?你怎么调用这个函数? – 2011-06-06 17:43:48

+0

url,名称和特性的值是什么? – 2011-06-06 17:44:23

+0

window.open不是一个jQuery函数 - 它是一个javascript – Hogan 2011-06-06 18:00:04

我们的代码......这里是修复:

var handle = wm.open(url,'I want a name!', 'location=0, menubar=0, resizable=1, scrollbars=1, status=0, toolbar=0, width=' + width + 'px, height=' + height + 'px, top=' + top + 'px , left=' + left + 'px'); 
+0

这不能解决任何问题(或者在正面上破坏任何东西)。 – Cheesel 2011-06-06 19:14:17

name参数不能有空格,所以正则表达式需要\s

this.getName = function (url) { 
    name = getAbsolutePath(url); 
    return name.replace(/[:.\+\/\?\&\=\#\%\-\s]/g, "_").toLowerCase(); 
};