【发布时间】:2014-12-12 11:26:38
【问题描述】:
我已将第三方代码集成到我的网站中,突然 setTimeout 和 setInterval 停止工作:在加载第三方之前,一切正常。预定在第三方加载后运行的 setTimeout 和 setInterval,根本不拖欠。 删除他们提供的第 3 方代码 sn-p 后,一切正常。
我的问题是 - 怎么可能?第三方可以做什么来阻止我的日程安排? 我重命名了任何指向 setTimeout 函数返回值的指针;我尝试使用放置 sn-p 和/或 setTimeout 代码的地方。 没有任何效果。
这没有任何意义。我不知道如何开始调试它。
这是一个简化的 html:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My Demo</title>
<link rel="shortcut icon" type="image/x-icon" href="img/favicon.ico"/>
<!--<link href="css/style.css" rel="stylesheet" type="text/css">-->
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
</head>
<body>
<script>
<!-- the alert pops up only when I remove the 3rd party snippet -->
setTimeout(function(){
alert("done");
}, 5000);
</script>
<!-- This is the 3rd party code -->
<script type="text/javascript">
var $P; var prefix = ('https:' == document.location.protocol ? 'https://' : 'http://'); var _P = _P || [];
_P.push(['setId', '123']);
var PPP = document.createElement('script');
PPP.type = 'text/javascript'; PPP.src = prefix + 'thethirdpartyIuse.com/functions.js';
var s = document.getElementsByTagName('script');
var lastScriptTag = s[s.length - 1];
lastScriptTag.parentNode.insertBefore(PPP, lastScriptTag);
</script>
</body>
</html>
感谢任何帮助和指导!
【问题讨论】:
-
我看不到任何代码周围的
$(document).ready({});... -
您是否尝试过从 alert() 更改为 console.log() ?您是否也尝试过设置断点并通过 firebug 进行调试以检查功能是否被覆盖?
-
附注:
<script>中的 HTML 注释无效。在<script>环境中使用JS cmets。 -
@Tomanow 在这种情况下不需要。
-
@Tomanow - 我为什么需要这个?无论如何。我在未简化的代码中有它。
标签: javascript html