5

使用Javascript加载页面时如何打开弹出新窗口?

我想,当一个网站加载时,它会自动打开弹出新窗口。

我使用以下内容:

<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>

不行??

4

4 回答 4

0

尝试这个-

<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>

将此代码粘贴到您网站的 head 部分。

于 2014-08-01T15:41:21.833 回答
0

你不能这样做。这是一个浏览器安全功能。尝试使用jQuery UI: Dialog

http://jqueryui.com/dialog/

例子:

    <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>

于 2014-05-06T19:59:18.023 回答
-1
<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>
于 2013-10-10T10:21:09.713 回答
-1
var newwindow;
function poptastic(url)
{
    newwindow=window.open(url,'name','height=400,width=200');
    if (window.focus) {newwindow.focus()}
}
于 2018-01-25T10:06:10.260 回答