在我的html頁面中(file:/// C:/Users/NEC/Desktop/test.html)有調用其他主機的javascript變量(或輸入文本字段)和iframe
(localhost:8081/TProject/sample的.html)。如何將數據從localhost的iframe設置爲離線html文件的父窗口變量?
在test.html的
<iframe src="localhost:8081/TProject/sample.html" ></iframe><br/>
<input type="text" id="output" ><br />
而且,在iframe
顯示我sample.html有跟隨javascript
代碼改變父窗口的輸入文本的價值。
function setData() {
window.parent.getElementById("output").value = "hello";
}
錯誤消息:
Uncaught SecurityError: Blocked a frame with origin "localhost:8081" from
accessing a frame with origin "null". The frame requesting access has a protocol of
"http", the frame being accessed has a protocol of "file". Protocols must match.
如何從在線服務器值(JavaScript變量)傳遞給離線的html頁面?
使用的postMessage()不同協議幀之間的交談。 – dandavis
類似的文章在http://stackoverflow.com/questions/5604839/accessing-an-element-outside-of-iframe – 2014-02-13 05:21:56
我的父頁面處於脫機狀態。所以我不能發送消息給使用postMessage()isFailed在'DOMWindow'上執行'postMessage'的父錯誤消息:提供的目標原點('http:// localhost:8081')與收件人窗口的原點不匹配'空值')。 –