Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
491 views
in Technique[技术] by (71.8m points)

javascript - How To Change a Popup Window's Location

I have a popup window being opened by my application as follows:

function newPopup(url, windowName) {
    window.open(url,windowName,'height=768,width=1366,left=10,top=10,titlebar=no,toolbar=no,menubar=no,location=no,directories=no,status=no');
}
<a href="JavaScript:newPopup('lobby.do', 'lobby');">Enter Lobby</a>

Inside that popup window, I want the user to have the ability to move that popup's window location by clicking a link:

<a href="game.do">New Game</a>

However, when click this link in the popup window, the popup is automatically closed and the redirect does not happen. I've tried adding an onClick and using javaScript:window.location, but get the same results. Any idea what could be causing this? I've tested in both Chrome and Firefox.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Just set the target of the link to the popup's name.

<a href="game.do" target="lobby">New Game</a>

Or save the value returned from window.open and set its .location.

function newPopup(url, windowName) {
    return window.open(url,windowName,'height=768,width=1366,left=10,top=10,titlebar=no,toolbar=no,menubar=no,location=no,directories=no,status=no');
}

<a onclick="window.lobby=newPopup('lobby.do', 'lobby'); return false;" href="#">Enter Lobby</a>
<a href="window.lobby.location='game.do'; return false;" href="#">New Game</a>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...