简体   繁体   English

如何使javascript中的弹出窗口仅显示一次?

[英]How to make popup window in javascript only show once?

I want to make single pop up window in javascript. 我想在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? 如何使用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. window.open方法采用3个参数。

  • 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? 为什么不使用内部iFrame创建内联页面弹出窗口(div)? Fancybox does this pretty easily along with a number of other frameworks. Fancybox与许多其他框架很容易做到这一点。 Pretty easy to write with custom Javascript as well. 使用自定义Javascript也很容易编写。

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');">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM