admin管理员组

文章数量:1332107

I want to make single pop up window in javascript. No matter how many times the button is pressed from parent page, only the single pop up is activated.

How can I do that in Javascript?

I want to make single pop up window in javascript. No matter how many times the button is pressed from parent page, only the single pop up is activated.

How can I do that in Javascript?

Share Improve this question edited Oct 5, 2011 at 1:54 Jared Farrish 49.2k17 gold badges99 silver badges107 bronze badges asked Oct 5, 2011 at 1:52 kitokidkitokid 3,11718 gold badges66 silver badges104 bronze badges 2
  • What is the purpose of the JSP tag? – Jared Farrish Commented Oct 5, 2011 at 1:53
  • I was going to suggest using a cookie, but I like the other solutions here instead because they don't require Cookies to be enabled which you can't always assume. – Yzmir Ramirez Commented Oct 5, 2011 at 2:02
Add a ment  | 

3 Answers 3

Reset to default 4

Just give the window a fixed name. So, don't do

window.open('popup.jsp');

but do

window.open('popup.jsp', 'chooseHereYourFixedName');

It will then be reused.

The window.open method takes 3 parameters.

  • a URL
  • a Name
  • a list of arguments

As long as the Name portion is the same when you open the popup, the same window will be reused.

window.open ("http://www.google.","mywindow","status=1");

Here's another idea.

Why not create an inline page popup (div) with an iFrame inside? Fancybox does this pretty easily along with a number of other frameworks. Pretty easy to write with custom Javascript as well.

This way your users will never navigate from your window and only that popup will ever live from clicking the button.

<script>
var popup;
</script>
<input type="button" onClick="if (!popup) popup = window.open('new.html');">

本文标签: How to make popup window in javascript only show onceStack Overflow