automatic open pop-up new window using Javascript [duplicate]

依然范特西╮ 提交于 2019-12-22 06:57:03

问题


How to open pop-up new window when load page using Javascript?

I want, when a website load, it will automatic open popup new window.

I use the following:

<script type="text/javascript">
function open_on_entrance(url,name)
{ 
   window.open('http://www.google.com','google', ' menubar,resizable,dependent,status,width=300,height=200,left=10,top=10')
}
</script>
<body onload="open_on_entrance()"></body>

Not work??


回答1:


You can't do this. It's a browser security feature. Try using jQuery UI: Dialog

http://jqueryui.com/dialog/

Example:

<html>
  <head>
      <meta charset="utf-8">
      <title>jQuery UI Dialog - Default functionality</title>
      <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
      <script src="//code.jquery.com/jquery-1.10.2.js"></script>
      <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
      <script>
      $(function() {
          $( "#dialog" ).dialog();
      });
      </script>
  </head>
  <body>
    <div id="dialog" title="Basic dialog">
        <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
    </div>
  </body>
</html>



回答2:


try this-

<script type="text/javascript">
window.onload = function() {
   window.open('http://upcominggames2015.blogspot.in/','new games release',' menubar=0, resizable=0,dependent=0,status=0,width=300,height=200,left=10,top=10')
}
</script>

Paste this code in head section of your website.




回答3:


<html>
<head>
<script type="text/javascript">
window.onload = function() {
   window.open('http://www.google.com','google',' menubar=0, resizable=0,dependent=0,status=0,width=300,height=200,left=10,top=10')
}
</script>
<body>
</body>
</head>
</html>



回答4:


var newwindow;
function poptastic(url)
{
    newwindow=window.open(url,'name','height=400,width=200');
    if (window.focus) {newwindow.focus()}
}


来源:https://stackoverflow.com/questions/19293014/automatic-open-pop-up-new-window-using-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!