document.write-javascript

document.write-javascript,javascript,Javascript,我想根据设备类型(移动/桌面)加载资源,我正在使用JS函数检测设备类型和document.write将资源写入HTML。此代码位于页面的中 <script type='text/javascript'> if (!is_mobile()) { document.writeln('<script type="text/javascript" src="/etc/designs/blabla-poc/js/bootstrap.min.js"><\

我想根据设备类型(移动/桌面)加载资源,我正在使用JS函数检测设备类型和document.write将资源写入HTML。此代码位于页面的

<script type='text/javascript'>
    if (!is_mobile()) {
        document.writeln('<script type="text/javascript" src="/etc/designs/blabla-poc/js/bootstrap.min.js"><\/script>');
    }else{
        document.writeln('<script type="text/javascript" src="js/bootstrap.min.js"><\/script>');
    }
</script>

如果(!is_mobile()){
书面文件(“”);
}否则{
书面文件(“”);
}
但是它写
document.writeln(“”)而不是


我做错了什么?

将标记拆分为更多字符串,以防止浏览器错误地理解它们

document.writeln('<scr' + 'ipt ... ></scr' + 'ipt>');
document.writeln(“”);
更新:

  • 破碎的:
  • 固定的:

我认为你所说的不可能发生。用
s=document.createElement('script')的“正确”方式做有什么不对;s、 类型='text/javascript';s、 src='…';document.documentElement.children[0]。appendChild?我猜他在寻找支撑方式:D@Pointy你能解释一下为什么吗?因为这根本不可能发生。是什么让你认为它正在发生?仔细看看你在问题中写的东西。这不是必须的。@Pointy真的吗?所有主要的浏览器(FF,IE,Chrome)都会在上面的演示中显示“断码”…唯一需要做的就是模糊OP发布的代码中已经完成的