Javascript href inside document.write表达式
我有一个脚本,可以检测用户是否正在使用internet explorer浏览web应用程序。如果是,我想写一个字符串并包含一个到chrome的链接。我的语法不正确Javascript href inside document.write表达式,javascript,Javascript,我有一个脚本,可以检测用户是否正在使用internet explorer浏览web应用程序。如果是,我想写一个字符串并包含一个到chrome的链接。我的语法不正确 <script> browsername = navigator.appName; if (browsername.indexOf("Microsoft") != -1) { browsername = "MSIE"; docu
<script>
browsername = navigator.appName;
if (browsername.indexOf("Microsoft") != -1) {
browsername = "MSIE";
document.write("You're viewing this page using Internet Explorer. Please use a supported browser ("<a href='https://www.google.com/chrome/browser/'</a>"Chrome)");
}
当然这是不正确的:
document.write("You're viewing this page using Internet Explorer. Please use a supported browser ("<a href='https://www.google.com/chrome/browser/'</a>"Chrome)");
通过在标签前放置,您将关闭第一个。您应该将引号转义到字符串中:
document.write("You're viewing this page using Internet Explorer. Please use a supported browser (\"<a href='https://www.google.com/chrome/browser/'></a>\"Chrome)");
编辑:甚至没有看到,但为什么铬在标签外面?不应该是Chrome吗?首先,您不应该使用document.write,因为如果页面已加载,它将用您编写的字符串替换所有内容 另一方面,您的语法错误,这是正确的代码:
document.write("You're viewing this page using Internet Explorer. Please use a supported browser (<a href='https://www.google.com/chrome/browser/'>Chrome</a>)");
我重写了你的剧本。。。你的问题太多了
if (navigator.userAgent.indexOf("MSIE") >= 0) {
browsername = "MSIE";
document.getElementById("ie-warning-placeholder").innerHTML('You\'re viewing this page using Internet Explorer. Please use a supported browser (<a href="https://www.google.com/chrome/browser/">such as Chrome</a>)');
}