我有一个奇怪的问题,谷歌广告( Google Ads )没有在IE8上显示(不是针对IE 8以下的版本进行测试)。
我使用了以下代码(使用中的jQuery)。
/*-- Advertizing --*/
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function(){
var script = $('<{0}></{0}>'.format('script'));
script.attr('type','text/javascript');
script.attr('async','async');
script.attr('src',document.location.protocol + '//www.googletagservices.com/tag/js/gpt.js');
$('head').eq(0).prepend(script);
googletag.cmd.push(function() {
googletag.defineSlot('/1016203/PG_194x662_Async', [194, 662], 'div-gpt-ad-1320434986666-0').addService(googletag.pubads());
googletag.defineSlot('/1016203/PG_530x99_Async', [530, 99], 'div-gpt-ad-1320435053303-0').addService(googletag.pubads());
googletag.defineSlot('/1016203/PG_530x50_Async', [530, 50], 'div-gpt-ad-1320435026691-0').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
googletag.cmd.push(function () { googletag.display('div-gpt-ad-1320434986666-0'); });
googletag.cmd.push(function () { googletag.display('div-gpt-ad-1320435053303-0'); });
googletag.cmd.push(function () { googletag.display('div-gpt-ad-1320435026691-0'); });
}());这是经过测试的,并且在IE9,Chrome,Firefox...但IE8是个例外。该网站位于photogallery.classiccars.com。(从DOM树上看) IE8中几乎加载了一个IFrame,但它只是丢失了。
发布于 2012-01-07 00:43:25
谷歌的代码使用的是for (var x in array),当Array.prototype被扩展时,它在一些浏览器中存在问题。
为什么他们不使用.length属性进行迭代,或者检查hasOwnProperty,我无法理解,但这似乎是手头的问题。
因为Backbone.js包含在需要Underscore.js的项目中,所以我调整了代码库,以便在项目中使用Underscore.js中的实用程序方法。
//instead of an ES5-Shim extension to Array.prototype.filter (for example)
var ary = [...];
//instead of this...
var results = ary.filter(function(item){...}); //es5
//use this
var results = _.filter(ary, function(item){...}); //underscore.js请注意,任何编写JavaScript的人,除非您显式检查hasOwnProperty,否则请避免使用for..in。这对数组和对象都适用。
var ary = [...];
for (var x in ary) {
if (!ary.hasOwnProperty(x)) continue; //skip inherited properties.
//your handling here
...
}https://stackoverflow.com/questions/8751620
复制相似问题