2012-07-20 43 views
2

我必須打開窗口上點擊按鈕作爲使用JavaScript的模式對話框。 我已經使用window.open,但它顯示了兩個實例的父頁面以及彈出頁面。 當彈出頁面打開時,不允許點擊父頁面。打開窗口上點擊按鈕作爲使用javascript的模態對話框

function openWindow() 
      { 
       var colno, pid; 
       var w = 950; 
       var h = 350; 
       var t = 0; 
       var l = 0; 
       var scrollbars = 1; 
       var modal = 'yes'; 

       var reportWindow = ""; 
       reportWindow = window.open("Search.aspx" + '', '', "width=" + w + ",height=" + h + ",left=" + l + ",top=" + t + ',scrollbars=' + scrollbars + 'modal' + modal); 
       reportWindow.focus(); 
       return false; 
      } 
+0

看到這可能是有幫助的您http://okonet.ru/projects/modalbox/index.html – 2012-07-20 07:32:49

回答

5

您的代碼行,

reportWindow = window.open("Search.aspx" + '', '', "width=" + w + ",height=" + h + ",left=" + l + ",top=" + t + ',scrollbars=' + scrollbars + 'modal' + modal); 

丟失後的模態的 '=' 符號。它應該是,

reportWindow = window.open("Search.aspx" + '', '', "width=" + w + ",height=" + h + ",left=" + l + ",top=" + t + ',scrollbars=' + scrollbars + 'modal=' + modal); 

要打開窗口,對話框,

<html> 
    <body> 
    <script language="JavaScript"> 
    function openWindow() { 
     if (window.showModalDialog) { 
window.showModalDialog("http://domain.com","name", 
"dialogWidth:255px;dialogHeight:250px"); 
} else { 
window.open('http://domain.com','name', 
'height=255,width=250,toolbar=no,directories=no,status=no, linemenubar=no,scrollbars=no,resizable=no ,modal=yes'); 
} 
    } 
    </script> 
    <button onclick="openWindow();">Open window</button> 
    </body> 
    </html> 

如果上面的代碼不能正常工作,請使用jQuery模態對話框。您可以使用iframe將任何網址加載到對話框中。

+0

再次閱讀問題。 '但它顯示了我的兩個實例父頁面以及彈出頁面。當彈出頁面打開,然後不允許點擊父頁面。' – 2012-07-20 07:25:30

+0

user970349 ::看我已經問問模式對話框在JavaScript中 – John 2012-07-20 07:32:14

+0

用戶window.showmodaldialog也不能作爲模式對話框工作我檢查它。 – 2012-07-20 07:34:04

2

「window.open」不起作用。這個命令總是打開一個彈出窗口,而不是「始終」在其父窗口之上。

2個選項:

  1. 如果你只想讓用戶輸入搜索字符串,你可以使用

    prompt("Please enter a search string:", ""); 
    
  2. 如果您有配合物搜索表單,你必須創建一個爲你自己的模態對話框。 有一些框架提供了這種功能(谷歌的「jQuery」),或者你自己創建它。不應該很難,告訴我,如果你需要一些幫助!

+0

PLEADE READ MY MY QUETION ATLEAST ONCE我必須打開模式彈出頁面按鈕單擊 – John 2012-07-20 07:35:19

+0

我做了,並且正如我告訴過你的,不可能使用window.open來保證安全,並使其在所有瀏覽器中都能正常工作。你必須使用jQuery或我們自己編寫的東西在JavaScript中生成模態windown。 – 2012-07-20 12:07:46

相關問題