为什么我的按钮会这样

Why does my button do this?

本文关键字:按钮 我的 为什么      更新时间:2024-02-17

它转到未定义,然后转到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>

您编写了

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

我本以为:

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

但我不确定它是否与您的pb 有关

因为您在这里使用了未向popup函数传递参数:

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

您应该传递一个参数,或者在函数未定义的情况下签入该函数,然后分配一些URL

试试这个:

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);
  }