0

这一行:

if(Debug===true){console.log('No jquery detected on host site, loading own jquery');}

在诺基亚 Windows 手机中破坏我的脚本,如果我将该变量设置为 false,则一切正常,但如果设置为 true,脚本将停止。我也尝试发出警报而不是那个 console.log 但同样的停止行为。

有人知道或怀疑这种行为的原因吗?

编辑

Tks 对于所有回复,事实是,如果我取出整个 console.log 行并在 if 例如我将其留空或者我放置一个简单的 var 声明,相同的停止行为仍然存在,这让我怀疑与if 语句比使用控制台对象

第二次编辑

正如你们所说的那样是事实,console.log 破坏了它,我有一个隐藏的,找到它并且现在可以工作,所以与 if 无关,而是来自控制台对象的所有错误,tkyou all

4

5 回答 5

4

我不会依赖consoleWindows 手机上存在的对象。您应该对您的声明进行防弹,以确保它不会爆炸:

if (Debug===true && typeof console !== 'undefined') {
    console.log('No jquery detected on host site, loading own jquery');
}
于 2012-10-09T13:59:26.033 回答
2

Console.Log并且Alert在 WP7 上不受支持。您确定这是诺基亚特有的,而不仅仅是 WP7 特有的吗?我还没有尝试过,但是这个可能有用。

于 2012-10-09T13:57:47.047 回答
1

嗯,这很奇怪。我不完全确定您为什么使用 if(Debug===true) 而不是 if(Debug) 甚至 if(debug==true)。=== 对于布尔值是不必要的。您可能想尝试一下,看看它是否能解决您的问题。

于 2012-10-09T13:56:19.390 回答
1

不要依赖console.log现有的。如果您要使用它,请先检查它是否已定义。

于 2012-10-09T13:57:19.217 回答
1

我相信旧版本的 Internet Explorer 默认情况下不会定义console。您可以通过以下方式检查是否console已定义:

if(Debug===true){
    if(!!console){
        console.log('No jquery detected on host site, loading own jquery');
    } else {
        window.console = { log: function(m){ alert(m); } } //Define console to prevent future errors.
        alert('No jquery detected on host site, loading own jquery');
    }
}
于 2012-10-09T13:57:28.553 回答