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