2014-06-17 53 views
0

我想限制用户打开我的应用程序的多个IFrame窗口。我的代码如下,window.open启动URL后返回null

<html> 
<head> 
<title>Test for Window Already Open</title> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
<script> 

var gmyWin=null; 

function myOpenWindow(winURL,winName,winFeatures,winObj) 
{ 
    var theWin; 
    theWin = window.open(winURL,winName,winFeatures); 
    // here theWin variable is null 
    return theWin; 
} 
</script> 
</head> 

<body> 
<h1>Click this link to open the new window:</h1> 
<p><a href='javascript:;' onClick='javascript:gmyWin=myOpenWindow("http://example:7001/tester/helloworld.jsp","myWin","height=630,width=1100",gmyWin);return false'>open new window</a> </p> 
</body> 

我尝试访问theWin变量,但它总是返回null。我想检查窗口是否打开,但我无法检查,打开URL后window.open返回null。 请帮我解决问题。

+0

你为什么不使用window.location的? –

回答

0

只需设置一个标志。

function myOpenWindow(winURL,winName,winFeatures,winObj) 
{ 
    var windowIsOpen = false; 
    window.open(winURL,winName,winFeatures); 
    windowIsOpen = true; 

    return windowIsOpen; 
} 
0

以及采取的变量的值,你可以返回一个布尔变量

<html> 
<head> 
<title>Test for Window Already Open</title> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
<script> 
function myOpenWindow(winURL,winName,winFeatures,winObj) 
{ 
    var windowOpen = false; 
    window.open(winURL,winName,winFeatures); 
    windowOpen = true; 

    return windowOpen; 
} 
</script> 
</head> 

<body> 
<h1>Click this link to open the new window:</h1> 
<p><a href='javascript:;' onClick='javascript:gmyWin= return myOpenWindow("http://example:7001/tester/helloworld.jsp","myWin","height=630,width=1100",gmyWin);return false'>open new window</a> </p> 
</body> 

必须添加一个return语句:l,布尔值

相关问题