从 Js 文件重定向
Redirect From a Js File
>我在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://google.com"
//-->
}
</script>
但是我想使用一个执行相同功能的JS文件,但它的扩展名应该.js
那么 http://domain.com/redirect.js 代码是什么?
这包括
一个带有回调的脚本包含函数,因此在加载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);
}
相关文章:
- AJAX不会在文件上传后重定向到网页-POST方法
- javascript:发送带有音频文件的POST,然后重定向到新页面
- 在发布表单输入时,我可以重定向到一个新的php文件吗
- javaScript警报和提示框将我重定向到另一个页面,上面写着“;找不到文件”;
- 包含导致重定向的空白javascript文件
- 从外部php文件重定向页面(在ajax调用中)
- 在Chrome扩展中使用PAC文件重定向HTTPS请求似乎失败了
- 我开发了一个api,我希望它重定向到其他php页面,并在我点击api文件中的按钮时弹出模态
- 快速发送文件和重定向 URL
- 将节点应用程序中的表单数据重定向到 PHP 文件
- 将 URL 重定向到子文件夹
- 防止在表单提交后重定向到 PHP 文件
- 如何重定向到文件
- 重定向前来自 java 文件的警报
- 如何在标头重定向之前通过 ajax 从 php 文件中检索信息
- 使用页面重定向的文件下载上的加载指示器
- 将 JS 文件添加到 web.config 中用于表单身份验证的例外文件列表中会导致无限重定向
- ZF2 从 phtml 文件重定向
- 如何使用基于引用的Javascript重定向js文件
- 在子文件夹中检测到浏览器后重定向