2010-12-13 50 views
1

我的JavaScript彈出窗口有問題。我有兩個窗口彈出功能:Javascript WIndows彈出功能衝突

第一個窗口彈出將打開一個新窗口包含頁面URL

樣子:

<a class="" onclick="kmt_contactFormPopup('http://uk.support.tomtom.com/app/ask',this)">[To the contact form..]</a> 



function kmt_contactFormPopup(emailURL, aTag) 
{ 
    params = 'width=950px'; 
    params +=',height=700'; 
    params += 'screenX=250, screenY=80,'; 
    params +='scrollbars=yes'; 
    newwindow=window.open(emailURL,'name',params); 

    if (newwindow.focus) {newwindow.focus()} 
} 

第二個窗口彈出將抓住內容在此HTML頁面中,並在彈出窗口中顯示內容。

例如;

Collect the error log <a href="#BOX01" onclick="kmt_ShowBoxPopup('BOX01', this);"><strong>[Show me how..]</strong></a><br /><br /> 
<div id="BOX01" style="display:none"> 
    <table cellspacing="0" cellpadding="0" border="0" style="background-color:#ffffff;"> 

     </tr> 
    </table> 
</div> 

JavaScript的

function kmt_ShowBoxPopup(targetDivID, aTag) 
    { 
    var orgin_div_content=document.getElementById(targetDivID).innerHTML; 

    showBoxPopupWin =window.open("",'name','height=400,width=710,screenX=250,screenY=80, scrollbars=yes'); 

    showBoxPopupWin.document.write (orgin_div_content); 

    if (window.focus) {showBoxPopupWin.focus()} 
} 

如果我運行聯繫形式彈出功能第一,然後我點擊showBox功能。我在JavaScript中的錯誤消息:

權限遭拒,從 獲取屬性Window.document 43

行是這行代碼

showBoxPopupWin.document.write (orgin_div_content); 

我想有不同的彈出視窗。

回答

1
showBoxPopupWin =window.open("",'name', ... 

不會在窗口中打開一個新的空白文檔寫如果調用'name'的窗口已經打開。它將保留舊文檔,這是一個外部鏈接,不能寫入。

您將不得不打開一個不同名稱的窗口(通常爲_blank,以防止任何窗口名稱衝突)。

(還要考慮與href,而不是JS-僅人造鏈接給你的局部變量var,以避免意外衝突世界,並使用正確的鏈接。)