我在我的网站中定义了以下功能.它适用于某些人,而不适用于其他人.该方法的最后一行发生异常,其中串联是.我相信,因为指定查询字符串的url的问号字符被视为三元运算符.
这里有什么东西我没有看到,或者有更好的方法来构建这个字符串?
url变量的值为:"mywebpage.aspx?AccountNumber = 123456"
function popUp(url) {
var myleft = (screen.width) ? (screen.width - 750) / 2 : 100;
var mytop = (screen.height) ? (screen.height - 300) / 2 : 100;
var id = new Date().getTime();
eval("page" + id + " = window.open(" + url + ", '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=900,height=325, top='" + mytop + "',left='" + myleft +");");
}
Run Code Online (Sandbox Code Playgroud)
Poi*_*nty 11
您将通过避免eval()以下内容消除"引号内的引号"问题:
window["page" + id] =
window.open(url, id, 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=900,height=325, top=' + mytop + ',left=' + myleft);
Run Code Online (Sandbox Code Playgroud)
您还应确保使用"id"值作为有效标识符(具体以非数字字符开头),否则Internet Explorer将抛出错误.