我有一个功能:
function getScript(src) {
document.write('<' + 'script src="' + src + '"' +
' type="text/javascript"><' + '/script>');
}
它被称为一次:
getScript("http://maps.gstatic.com/intl/sv_se/mapfiles/api-3/3/1b/main.js");
})();
我需要摆脱document.write,因为在firefox中的xhtml中不支持它。我该怎么做呢? jQuery很好:)
完整代码:
window.google = window.google || {};
google.maps = google.maps || {};
(function() {
function getScript(src) {
document.write('<' + 'script src="' + src + '"' +
' type="text/javascript"><' + '/script>');
}
var modules = google.maps.modules = {};
google.maps.__gjsload__ = function(name, text) {
modules[name] = text;
};
google.maps.Load = function(apiLoad) {
delete google.maps.Load;
apiLoad([null,[[["http://mt0.google.com/vt?lyrs=m@139\u0026src=api\u0026hl=sv-SE\u0026","http://mt1.google.com/vt?lyrs=m@139\u0026src=api\u0026hl=sv-SE\u0026"]],[["http://khm0.google.com/kh?v=74\u0026hl=sv-SE\u0026","http://khm1.google.com/kh?v=74\u0026hl=sv-SE\u0026"],null,null,null,1],[["http://mt0.google.com/vt?lyrs=h@139\u0026src=api\u0026hl=sv-SE\u0026","http://mt1.google.com/vt?lyrs=h@139\u0026src=api\u0026hl=sv-SE\u0026"],null,null,"imgtp=png32\u0026"],[["http://mt0.google.com/vt?lyrs=t@126,r@139\u0026src=api\u0026hl=sv-SE\u0026","http://mt1.google.com/vt?lyrs=t@126,r@139\u0026src=api\u0026hl=sv-SE\u0026"]],null,[[null,0,7,7,[[[330000000,1246050000],[386200000,1293600000]],[[366500000,1297000000],[386200000,1320034790]]],["http://mt0.gmaptiles.co.kr/mt?v=kr1.12\u0026hl=sv-SE\u0026","http://mt1.gmaptiles.co.kr/mt?v=kr1.12\u0026hl=sv-SE\u0026"]],[null,0,8,9,[[[330000000,1246050000],[386200000,1279600000]],[[345000000,1279600000],[386200000,1286700000]],[[348900000,1286700000],[386200000,1293600000]],[[354690000,1293600000],[386200000,1320034790]]],["http://mt0.gmaptiles.co.kr/mt?v=kr1.12\u0026hl=sv-SE\u0026","http://mt1.gmaptiles.co.kr/mt?v=kr1.12\u0026hl=sv-SE\u0026"]],[null,0,10,19,[[[329890840,1246055600],[386930130,1284960940]],[[344646740,1284960940],[386930130,1288476560]],[[350277470,1288476560],[386930130,1310531620]],[[370277730,1310531620],[386930130,1320034790]]],["http://mt0.gmaptiles.co.kr/mt?v=kr1.12\u0026hl=sv-SE\u0026","http://mt1.gmaptiles.co.kr/mt?v=kr1.12\u0026hl=sv-SE\u0026"]],[null,3,7,7,[[[330000000,1246050000],[386200000,1293600000]],[[366500000,1297000000],[386200000,1320034790]]],["http://mt0.gmaptiles.co.kr/mt?v=kr1p.12\u0026hl=sv-SE\u0026","http://mt1.gmaptiles.co.kr/mt?v=kr1p.12\u0026hl=sv-SE\u0026"]],[null,3,8,9,[[[330000000,1246050000],[386200000,1279600000]],[[345000000,1279600000],[386200000,1286700000]],[[348900000,1286700000],[386200000,1293600000]],[[354690000,1293600000],[386200000,1320034790]]],["http://mt0.gmaptiles.co.kr/mt?v=kr1p.12\u0026hl=sv-SE\u0026","http://mt1.gmaptiles.co.kr/mt?v=kr1p.12\u0026hl=sv-SE\u0026"]],[null,3,10,null,[[[329890840,1246055600],[386930130,1284960940]],[[344646740,1284960940],[386930130,1288476560]],[[350277470,1288476560],[386930130,1310531620]],[[370277730,1310531620],[386930130,1320034790]]],["http://mt0.gmaptiles.co.kr/mt?v=kr1p.12\u0026hl=sv-SE\u0026","http://mt1.gmaptiles.co.kr/mt?v=kr1p.12\u0026hl=sv-SE\u0026"]]],[["http://cbk0.google.com/cbk?","http://cbk1.google.com/cbk?"]],[["http://khmdb0.google.com/kh?v=33\u0026hl=sv-SE\u0026","http://khmdb1.google.com/kh?v=33\u0026hl=sv-SE\u0026"]],[["http://mt0.google.com/mapslt?hl=sv-SE\u0026","http://mt1.google.com/mapslt?hl=sv-SE\u0026"]],[["http://mt0.google.com/mapslt/ft?hl=sv-SE\u0026","http://mt1.google.com/mapslt/ft?hl=sv-SE\u0026"]]],["sv-SE","US",null,0,null,"http://maps.google.com","http://maps.gstatic.com/intl/sv_se/mapfiles/","http://gg.google.com","https://maps.googleapis.com","http://maps.googleapis.com"],["http://maps.gstatic.com/intl/sv_se/mapfiles/api-3/3/1b","3.3.1b"],[4241463462],1,null,null,null,null,0,""], loadScriptTime);
};
var loadScriptTime = (new Date).getTime();
getScript("http://maps.gstatic.com/intl/sv_se/mapfiles/api-3/3/1b/main.js");
})();
最佳答案
您为什么不将其放入文档中?
<script src="http://maps.gstatic.com/intl/sv_se/mapfiles/api-3/3/1b/main.js">
</script>
如果需要您在完成其余操作后加载脚本,请将两个脚本标签都放在正文的末尾(googlemaps脚本作为第二个)