从iframe中获取价值,而不是在Chrome或Firefox中工作

Getting value from iframe working in IE but not Chrome or Firefox

本文关键字:Chrome Firefox 工作 获取 iframe      更新时间:2023-09-26

我正在使用带有STM32F4的 lwip tcp/ip 堆栈来为我的设备托管一个小型配置网站。我正在刷新页面上隐藏的 iframe 以获取更新的 SSI 值,然后在我的 tmp 变量中使用它们来更新图形。下面的代码在IE中效果很好,但在Firefox和Chrome中tmp只能获得一次值,即使temptemp元素从我的固件中获取更新的值。

var iframe = document.getElementById("iframeID");
var innerdoc = (iframe.contentWindow || iframe.contentDocument);
if(innerdoc.document)innerdoc = innerdoc.document;
(function worker() {
  $.ajax({
    url: 'data.shtml', 
    complete: function() {
      document.getElementById("iframeID").contentWindow.location.reload();
      setTimeout(worker, 1000);
      tmp = innerdoc.getElementById("temptemp").value;
    }
  });
})();
"

域、协议和端口必须匹配。

在Firefox和Chrome中运行它时,您是否检查过控制台是否有错误?我想你被告知你不能访问不安全的JavaScript。也许Internet Explorer对它如何运行JavaScript不安全是可以的。