我有一个Javascript代码来确定客户端的窗口宽度并显示桌面添加或移动添加。如果窗口超过600px,则显示桌面添加;否则显示移动添加。这是代码:
<script type="text/javascript">
var w = window,
d = document,
e = d.documentElement,
g = d.getElementsByTagName('body')[0],
x = w.innerWidth || e.clientWidth || g.clientWidth,
y = w.innerHeight || e.clientHeight || g.clientHeight;
if (x > 600) {
var uri = "http://impes.tradedoubler.com/imp?type(js)pool(34434)a(54665)" + new String(Math.random()).substring(2, 11);
document.write('<sc' + 'ript type="text/javascript" src="' + uri + '" charset="ISO-8859-1"></sc' + 'ript>');
if (x > 1119) {
document.write('<br />');
} else {
document.write(' ');
}
var uri = "http://impes.tradedoubler.com/imp?type(js)pool(34434)a(4543545)" + new String(Math.random()).substring(2, 11);
document.write('<sc' + 'ript type="text/javascript" src="' + uri + '" charset="ISO-8859-1"></sc' + 'ript>');
} else {
document.write('<sc' + 'ript async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></sc' + 'ript><!-- vesion_movil --><ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-345445454545" data-ad-slot="36543655" data-ad-format="auto"></ins>');
document.write('<sc' + 'ript>(adsbygoogle = window.adsbygoogle || []).push({});</sc' + 'ript>');
}
</script>
这通常是正常的,但有时,当使用移动设备(窗口宽度小于400px)访问网站时,我看到桌面版本,响应版本已损坏。知道为什么会发生什么事吗?