如何在弹出窗口中打开弹出窗口?

时间:2014-10-09 10:18:43

标签: javascript html popup

我想在另一个窗口打开弹出窗口打开弹出窗口。

请检查代码 -

myjavascript.js

var win = null;
function NewWindow(mypage,myname,w,h,scroll){
    LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
    TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
    settings =
    'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
    win = window.open(mypage,myname,settings)
}

的index.html

<script src="myjavascript.js"></script>
<a href="#" onclick="NewWindow('popup1.html','name','500','500','yes');return false" class="link-2">My Account</a>

popup1.html

<script src="myjavascript.js"></script>
<a href="#" onclick="NewWindow('popup2.html','name','500','500','yes');return false" class="link-2">Click to open popup2</a>

popup2.html

<h1>You are now popup2.html page</h1>

上面的代码对我有用,但第二个弹出窗口没有打开。请检查并告诉我。

由于 @chatfun

1 个答案:

答案 0 :(得分:1)

问题是您为window.open(mypage,myname,settings)使用了相同的标识符。

更改第二次调用中的name

<强>的index.html

<a href="#" onclick="NewWindow('popup1.html','name','500','500','yes');return false" class="link-2">My Account</a>

<强> popup1.html

<a href="#" onclick="NewWindow('popup2.html','NEWNAME','500','500','yes');return false" class="link-2">Click to open popup2</a>

希望这有帮助,