Javascript compatibility issues (code works in FF but not in Opera and Chrome)

☆樱花仙子☆ 提交于 2019-12-11 08:23:36

问题


I have a code in Javascript as follows...

var btnOK = document.getElementById('btnOK');
btnOK.style.visibility = "visible";
var iframeControlObj = document.getElementById('iframe');
this.style.visibility = "hidden";
var file_xml = iframeControlObj.contentDocument.getElementById('hiddenxml');
file_xml.value = xml_value;
iframeControlObj.contentWindow.location.reload();

Explanation

I have an iframe in which there is a control "hiddenxml". I want to send the data into the iframe from the current webpage. So, I am initializing the value to the "hiddenxml" and reloading the iframe.

Problem

In Firefox, I am able to get "xml_value" through the "hiddenxml", but in Chrome and Opera, I am unable to get this information it.

Please let me know why this is happening. If this is a trash method, please feel free to give a better method and improve it. Thanks a lot..

PS: The xml_value can be quite large, about 3-4 MB in size. xml_value is a string and not a DOM object


回答1:


If you want to exchange data between your page and an iframe you can use

window.postMessage

The Mozilla Documentation about this is quite good: https://developer.mozilla.org/en-US/docs/Web/API/Window.postMessage

Maybe this will help you.



来源:https://stackoverflow.com/questions/21950656/javascript-compatibility-issues-code-works-in-ff-but-not-in-opera-and-chrome

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!