javascript - IE 说 javascript 函数未定义,但它在 Chrome 中工作正常

标签 javascript html cross-browser

我有一个包含链接的网页 - 打开一个显示 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(); 
    }

在 body 里我有:

<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安全区问题,还是编码错误?

最佳答案

两件事:

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

关于javascript - IE 说 javascript 函数未定义,但它在 Chrome 中工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51755996/

相关文章:

javascript - 在 Azure 应用服务上使用 Node 和 Express 进行路由

javascript - 如果日期相同则运行函数

javascript - 根据所选的下拉菜单自动填充文本框

javascript - 使用ajax/php在表单上显示消息

html - 如何不使 href 链接中的文本着色但文本也在 div 中?

php - FPDF 中的图像对齐错误

javascript - 提交 HTML 表单而不打开新窗口

html - CSS:如何使用 CSS(无 JavaScript、动态宽度和高度、不更改 HTML)在#header 和#content 之间向上移动#thumbnails?

math - 向我展示 webkitConvertPointFromPageToNode 的 Javascript 实现

css - 如何实现跨上下文CSS图像光标?