簡體   English   中英

Javascript彈出窗口在一頁上有效,但在另一頁上無效

[英]Javascript popup window, works on one page, but not on another

我在網站的多個頁面上都有一個javascript彈出窗口。 我使用了居中彈出窗口,該窗口在“ 居中顯示”屏幕上找到?

function popupwindow(url, title, w, h) {
    var left = (screen.width/2)-(w/2);
    var top = (screen.height/2)-(h/2);
    return window.open(url, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
}

此彈出窗口在某些頁面上有效,但在其他頁面上不可用...

我制作了2頁要顯示的內容,在第一頁上顯示彈出窗口的內容
http://www.weddingpages.nl/test1.php
在第二頁上,彈出窗口不起作用:
http://www.weddingpages.nl/test2.php

頁面的來源完全相同(復制,粘貼),僅在第二頁上我刪除了表單。

因此,如果我理解正確,那么此彈出式JavaScript僅在頁面上還有表單時才有效嗎?

這是彈出窗口所在頁面的代碼:

<!DOCTYPE html>
<html>
    <head>
        <title>test1</title> 
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

        <script type="text/javascript">
            function popupwindow(url, title, w, h) {
                var left = (screen.width/2)-(w/2);
                var top = (screen.height/2)-(h/2);
                return window.open(url, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
            }
        </script>
    </head>
    <body>
        <form class="form-horizontal" action="" method="post">
            <div class="control-group">
                <label class="control-label" for="title">Naam website / bedrijf:</label>
                <div class="controls">
                    <input type="text" class="span3" id="title" name="title" placeholder="Naam website / bedrijf">
                </div>
            </div>
            <div class="control-group">
                <div class="controls">
                    <button type="submit" name="submit" class="btn">Gegevens opslaan</button>
                </div>
            </div>
        </form> 
        <a href="javascript:popupwindow('http://www.google.com/', title, 1400, 700)">centered Pop up window</a> 
    </body>
</html>

因此,如果您刪除表格,則javascript將停止工作。

有誰能告訴我為什么? 我已經嘗試了將近2天的解決方案:-(

在將其傳遞給函數之前,您尚未定義“標題”參數。 嘗試更改此:

<a href="javascript:popupwindow('http://www.google.com/', title, 1400, 700)">centered Pop up window</a> 

有了這個

<a href="javascript:popupwindow('http://www.google.com/', 'real title', 1400, 700)">centered Pop up window</a> 

看起來您需要將title更改為其他title ,因為title是表單中的元素。

<a href="javascript:popupwindow('http://www.google.com/', title, 1400, 700)">centered Pop up 
window</a> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM