我正在使用JavaScript代碼在我的頁面中顯示廣告。如下圖所示爲相應的廣告顯示的JavaScript代碼:Javascript與string.replace方法衝突
var ad = {
encode: function(str) {
return escape(this._utf8_encode(str));
},
_utf8_encode: function(str) {
str = str.replace(/\r\n/g, "\n");
var utftext = "";
for (var n = 0; n < str.length; n++) {
var c = str.charCodeAt(n);
if (c < 128) {
utftext += String.fromCharCode(c);
}
else if ((c > 127) && (c < 2048)) {
utftext += String.fromCharCode((c >> 6) | 192);
utftext += String.fromCharCode((c & 63) | 128);
}
else {
utftext += String.fromCharCode((c >> 12) | 224);
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
utftext += String.fromCharCode((c & 63) | 128);
}
}
return utftext;
}
}
var partnerId = "b7241ebe72fa74ce";
var siteId = "11738";
var targetparams = new Array();
targetparams['ad_platform'] = "ros";
var targetparams_str = "";
for (var key in targetparams) {
if (targetparams_str != "") {
targetparams_str += "||";
}
targetparams_str += ad.encode(key) + "=>" + ad.encode(targetparams[key]);
}
targetparams_str = ad.encode(targetparams_str);
var m3_u = 'http://ads.admarvel.com/fam/javascriptGetAd.php';
var m3_r = Math.floor(Math.random() * 99999999999);
document.write("<scr" + "ipt type='text/javascript' src='" + m3_u);
document.write("?partner_id=" + partnerId);
document.write('&site_id=' + siteId);
document.write('&target_params=' + targetparams_str);
document.write('&version=1.5');
document.write('&language=javascript');
document.write('&format=wap');
document.write('&cb=' + m3_r);
document.write("'><\/scr" + "ipt>");
上面的代碼是在HTML主體中的元件內部。 現在在我的頁面我想包括一個外部js庫protoaculous.1.8.2.min.js當我把這個js文件放在頭上時,不知何故,我的廣告消失了,但只要我刪除了外部庫,廣告就會顯示出來。
我頁的概要如下:
<head>
<script type="text/javascript" src="http://www.ectnews.com/shared/ajax/protoaculous.1.8.2.min.js"></script>
<body>
<div>
//Javascript code for the ad display
</div>
</body>
以下是我在測試服務器上創建的鏈接到場景:
非工作HTML:
http://m.smartdevicemedia.com/test_external_js.htm
Working html:
http://m.smartdevicemedia.com/test_external_js_good.htm
你可以縮小嗎?看不到一半的代碼。 –