JavaScript兼容性问题(代码可在FF中使用,但不能在Opera和Chrome中使用) [英] Javascript compatibility issues (code works in FF but not in Opera and Chrome)
问题描述
我在Javascript中有一个代码如下:
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();
说明
我有一个iframe其中有一个控件hiddenxml。我想将数据从当前网页发送到iframe。因此,我将值初始化为hiddenxml并重新加载iframe。
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.
,我能够通过hiddenxml获得xml_value,但在Chrome和Opera,我无法获得这个信息。
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:xml_value可能相当大,大小约3-4 MB。 xml_value是一个字符串而不是DOM对象
PS: The xml_value can be quite large, about 3-4 MB in size. xml_value is a string and not a DOM object
推荐答案
如果你想在页面和iframe之间交换数据, / p>
If you want to exchange data between your page and an iframe you can use
window.postMessage
有关这方面的Mozilla文档相当不错: https ://developer.mozilla.org/en-US/docs/Web/API/Window.postMessage
The Mozilla Documentation about this is quite good: https://developer.mozilla.org/en-US/docs/Web/API/Window.postMessage
也许这会帮助你。
这篇关于JavaScript兼容性问题(代码可在FF中使用,但不能在Opera和Chrome中使用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!