Php 从Js文件重定向
我在php或html文件中使用此代码进行重定向Php 从Js文件重定向,php,javascript,html,Php,Javascript,Html,我在php或html文件中使用此代码进行重定向 <script language="JavaScript" src="http://j.maxmind.com/app/geoip.js"></script> <script language="JavaScript"> var country= geoip_country_code(); if(country == "US" ) { <!-- window.location = "http://g
<script language="JavaScript" src="http://j.maxmind.com/app/geoip.js"></script>
<script language="JavaScript">
var country= geoip_country_code();
if(country == "US" )
{
<!--
window.location = "http://google.com"
//-->
}
</script>
var country=geoip_country_code();
如果(国家=“美国”)
{
}
但是我想使用一个js文件,它具有相同的功能,但是它的扩展名应该是.js
同样,代码是什么?这包括一个带有回调的脚本include函数,以便在加载Maxmind库之前,Maxmind客户端代码不会运行
loadScript("http://j.maxmind.com/app/geoip.js", function() {
var country = geoip_country_code();
if (country === "US") {
window.location = "http://google.com/";
}
});
function loadScript(url, callback) {
// adding the script tag to the head as suggested before
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
// then bind the event to the callback function
// there are several events for cross browser compatibility
script.onreadystatechange = callback;
script.onload = callback;
// fire the loading
head.appendChild(script);
}
让我知道的最好办法是投票,选择我的答案作为正确答案。:)