2014-02-26 24 views
1

我使用以下來發布信息,並且當我創建表單元素時,我得到一個異常:「權限被拒絕」。嘗試將信息發佈到某個其他頁面時,權限被拒絕?

var newWindow = window.open('', '_blank', 'alwaysRaised=yes,toolbars=no, menubar=no, location=no, scrollbars=yes, resizable=yes, status=yes,left=10000, top=10000, width=10, height=10, visible=none', ''); 

var tempFormElement = newWindow.document.createElement('form'); 
tempFormElement.method = 'post'; 
tempFormElement.action = urlToOpen; 

var tempInputElement; 
tempInputElement = newWindow.document.createElement('input'); 
tempInputElement.setAttribute('TPLInfo', JSON.stringify(linkageInfo)); 
tempFormElement.appendChild(tempInputElement); 
tempFormElement.submit(); 

newWindow.document.body.removeChild(tempFormElement); 
newWindow.close(); 

請建議。

+0

@mplungjan - 有什麼你可以設置該項行動(雖然它可能會導致最後兩行的問題)沒有任何限制,而OP說的錯誤是在此之前,兩行反正。 – Quentin

+0

在爲缺少的變量添加數據後,我無法重現該問題。唯一的錯誤是試圖從body刪除tempFormElement(因爲你從未將它添加到body)。 – Quentin

+0

您可以在網絡服務器上打開一個小於10px的pos 10000窗口? – mplungjan

回答

1
  1. 由於安全限制,大多數瀏覽器現在也不會允許你查看端口之外創建一個新的窗口或小於100×100
  2. 你不需要打開新窗口 - 而不是使用AJAX
  3. 如果因爲urlToOpen在另一個域上而無法使用AJAX,則無論如何您都無法關閉窗口或刪除該tempform元素。
  4. 你不能做到這一點在同一個起源要麼因爲它是提交後不再有
  5. 有一個名爲TPLInfo

輸入元素沒有有效的財產所以我建議 - 如果可以的話:

Ajax的使用jQuery

$.post(urlToOpen,{"TPLInfo":JSON.stringify(linkageInfo)}); 

,或者如果不是在相同的域(純JS):

Live Demo

var newWindow; 
var urlToOpen = "...."; 
function perform() { 
     if (!newWindow) { 
     alert("Sorry, you must allow popups"); 
     return; 
     } 
     var tempFormElement = newWindow.document.createElement('form'); 
     tempFormElement.method = 'post'; 
     tempFormElement.action = urlToOpen; 
     var tempInputElement; 
     tempInputElement = newWindow.document.createElement('input'); 
     tempInputElement.setAttribute("name","TPLInfo"); 
     tempInputElement.value = JSON.stringify({"a":"1"}); 
     tempFormElement.appendChild(tempInputElement); 
     newWindow.document.body.appendChild(tempFormElement); 
     tempFormElement.submit(); 
} 
window.onload=function() { 
    document.getElementById("but").onclick=function() { 
// var parms = "alwaysRaised=yes,toolbars=no,menubar=no,location=no,scrollbars=yes,resizable=yes,status=yes,left=10000,top=10000,width=10,height=10,visible=none"; 
     // valid parms, yes I know you want to hide and close but nope. 
     var parms = "scrollbars,resizable,status,left=10000,top=10000,width=100,height=100"; 

     newWindow = window.open('', '_blank',parms); 
     setTimeout(perform,500); // give IE time to get over opening 
    } 
} 
相關問題