-2

它转到未定义,然后转到 test.com。

我怎样才能让它去http://url.com然后http://test.com 然后http://anotherdesiredurl.com

<head>

<script type="text/javascript">
        <!--
        function popup(url) {

            var width = 300;
            var height = 200;
            var left = (screen.width - width) / 2;
            var top = (screen.height - height) / 2;
            var params = 'width=' + width + ', height=' + height;
            params += ', top=' + top + ', left=' + left;
            params += ', directories=no';
            params += ', location=no';
            params += ', menubar=no';
            params += ', resizable=no';
            params += ', scrollbars=no';
            params += ', status=no';
            params += ', toolbar=no';
            newwin = window.open(url, 'popup', 'params');
            if (window.focus) {
                newwin.focus()
            }

            return false;

        }
setTimeout(function() {popup('http://www.test.com/'); }, 8000)


        //-->
        //]]>
    </script>


<head>
<body>
<input type="button" value="Click Blitch" onclick="popup();"/>
</body>
4

3 回答 3

1

你写了

newwin = window.open(url, 'popup', 'params');

我本来期望:

newwin = window.open(url, 'popup', params);

但我不确定这与你的铅有关

于 2012-07-24T07:59:45.680 回答
0

because you use haven't passed an argument to popup function here:

<input type="button" value="Click Blitch" onclick="popup();"/>

you should either pass an argument, or check in the function if it is undefined, then assign some URL

于 2012-07-24T07:57:32.940 回答
0

尝试这个:

JavaScript

function popup(url) {

    var width = 300;
    var height = 200;
    var left = (screen.width - width) / 2;
    var top = (screen.height - height) / 2;
    var params = 'width=' + width + ', height=' + height;          
    params += ', top=' + top + ', left=' + left;
    params += ', directories=no';
    params += ', location=no';
    params += ', menubar=no';
    params += ', resizable=no';
    params += ', scrollbars=no';
    params += ', status=no';
    params += ', toolbar=no';
    newwin = window.open(url, 'popup', 'params');
    if (window.focus) {
      newwin.focus()
    }

    return false;

  }

  function openWindows() {
    popup('http://url.com');
    popup('http://text.com');
    popup('http://http://anotherdesiredurl.com');
  }

HTML

<input type="button" value="Click here" onclick="openWindows();"/>

如果要在超时后更改同一弹出窗口的位置,可以将 JavaScript 更改为此:

  function popup(url, win) {

    var width = 300;
    var height = 200;
    var left = (screen.width - width) / 2;
    var top = (screen.height - height) / 2;
    var params = 'width=' + width + ', height=' + height;
    var newwin = win;
    params += ', top=' + top + ', left=' + left;
    params += ', directories=no';
    params += ', location=no';
    params += ', menubar=no';
    params += ', resizable=no';
    params += ', scrollbars=no';
    params += ', status=no';
    params += ', toolbar=no';
    if (newwin) {
      newwin.location = url;
    } else {
        newwin = window.open(url, 'popup', 'params');
    }
    if (window.focus) {
      newwin.focus()
    }

    return newwin;

  }

  function openWindows() {
    var win = popup('http://url.com');
    setTimeout(function () {
        popup('http://text.com', win);
    }, 2000);
    setTimeout(function () {
        popup('http://http://anotherdesiredurl.com', win);
    }, 4000);
  }
于 2012-07-24T08:01:32.857 回答