【问题标题】:IE says javascript function is undefined, but it works in Chrome OKIE 说 javascript 函数未定义,但在 Chrome 中可以正常工作
【发布时间】:2019-01-16 06:26:27
【问题描述】:

我有一个包含链接的网页 - 打开一个显示 YouTube 视频的新窗口。它在 Chrome 中运行良好,但在 IE 中它不起作用。 IE 控制台显示:SCRIPT5009: 'open_win' is undefined(我使用的是 IE11)

在头部我有:

function open_win(url)
   {
   new_window = open('','video','width=500,height=390,menubar=no,status=no,location=no,toolbar=no,scrollbars=yes');
   // open new document 
    new_window.document.open();
    // Text of the new document 
    new_window.document.write("<html><head></head><body style='background-color:'black';margin-top:0; margin-right:0; margin-bottom:0; margin-left:0;'>");
    new_window.document.write("<iframe width='560' height='315' src='https://www.youtube.com/embed/-linkRedacted-' frameborder='0' allow='autoplay; encrypted-media' allowfullscreen></iframe>");
    new_window.document.write("</body></html>");
    // close the document
    new_window.document.close(); 
    }

在我的身体里:

<a class="audio" href="javascript:void(0)" onclick="open_win()">
<img alt="See a demo video (opens in New window)" src="images/demo.jpg" width="120" height="110" /></a>

是 IE 安全区域问题,还是编码错误?

【问题讨论】:

  • 太棒了 - 你有答案 - 谢谢!知道为什么找不到它(这肯定是这样的函数应该驻留的地方吗?)
  • 发布的解决方案似乎消失了;?是将功能从头部转移到身体部分。
  • 它应该可以在任何地方工作。
  • 代码在&lt;script&gt;...&lt;/script&gt;里面吗?
  • 好吧@Barmar - 解决方案(似乎已经从视图中消失了;?)说IE11在头部找不到功能。所以,我把它移到 并且它现在可以工作了。而且,很高兴能说明这一点……它在

标签: javascript html cross-browser


【解决方案1】:

两件事:

  • 您是否在 javascript 中使用严格?也许如果你正在使用 严格的 IE11 不喜欢你调用一个函数而不传递 函数变量。
  • javascript 是否在单独的文件中。也许尝试将您的函数复制到您的 html 上方,看看它是否有所作为

【讨论】:

  • 好主意,但我有:ttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" rel="nofollow" target="_blank">w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> w3.org/1999/xhtml" dir="ltr" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">。我已经尝试过传递/不传递变量。
  • 并且javascript在页面的头部。
  • 您最终是否通过从 head 部分删除您的 javascript 来解决此问题?
  • 我尝试将 js 放在页面底部的 head 部分,它在我遇到问题的 IE11 中有效。谢谢。
猜你喜欢
  • 2020-08-31
  • 1970-01-01
  • 1970-01-01
  • 2014-04-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-15
相关资源
最近更新 更多