Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How can I modify this so it checks and if a popup window is already open?

function popUp(URL) {
  day = new Date();
  id = day.getTime();
  eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=350,height=100');");
}

/////////////Edit No2

var options = "toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=350,height=100";

var popup = window.open(URL, "popup", options);

function popUp(URL) { day = new Date(); id = day.getTime(); eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=350,height=100');"); }

My js call

<a id="floating_link" href="javascript:popUp('MyPage.html')">Player</a>

See Question&Answers more detail:os

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

1 Answer

Use the same id for the window, which is the name of the window, to reuse it if it exists.

http://www.w3schools.com/jsref/met_win_open.asp

var options = "toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=350,height=100";
var popup = window.open(URL, "popup", options);

To do this with an anchor tag you just set the target

If you set an anchor tag's target target="myopup" it will use that same window if it exists


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...