开发者

How to make popup window in javascript only show once?

I want to make sing开发者_JAVA百科le 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?


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.com","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');">
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜