简体   繁体   English

Javascript自动弹出(无需单击按钮)

[英]Javascript auto popup (without clicking a button)

I was just wondering if it is possible to display a javascript message (either popup or something nice) which is triggered by something which isn't a mouse click, so for example: 我只是想知道是否有可能显示不是通过鼠标单击触发的javascript消息(弹出式窗口或类似的东西),例如:

<?php if(a == b) {
    Then auto pop up something
}

I have had a look around and cant seem to find anything, also how do people make like stylistic popups like.. i guess maybe CSS but really fancy ones which cant be done with CSS any ideas? 我环顾四周,似乎找不到任何东西,人们又如何像样式弹出式窗口一样..我想也许是CSS,但是真的很花哨,无法用CSS完成任何构想?

Thanks a bunch :) 谢谢一大堆:)

Just add a script block to open an alert or what ever you need to open 只需添加脚本块即可打开警报或您需要打开的内容

<?php if(a == b) { ?>
    <script>
          alert('hello');
          // or
          window.open("http://wwwstackoverflow.com");
          // or any type of script you want to run

    </script>
<?php } ?>

For anyone coming here these days: window.open() called like that will be blocked by any modern browser. 对于这些天来这里的人:像这样调用的window.open()将被任何现代浏览器阻止。

If you're okay with including a third-party script , you can do this instead: 如果可以包含第三方脚本 ,可以改为执行以下操作:

<?php if(a == b) { ?>
  <script>
    Popup("<div>Hello</div>").show('up')
  </script>
<?php } ?>

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

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