我正在寻找一个简单的代码,可以将用户转发到URL中指定的另一个URL:
示例:
http://example.com/index.php?URL=anothersite
用户登录http://example.com/index.php并且在5秒之后被转发到另一个站点
有人能帮我吗?
JS示例:
setTimeout(function(){
var pair = (window.location.search.split("&")[0] || "").split("=");
if( (pair[0] || "").toUpperCase() != "?URL") return;
window.location = pair[1];
},5000);
尝试在querystring中设置重定向目标,然后使用javascript进行重定向!
网址:http://example.com/index.php?URL=anothersite
<html>
<head>
<script>
setTimeout(function() {
var match = /['?&]url=([^&]*)/.exec(location.search);
if(match && match[1]) location.replace(match[1]);
}, 5000);
</script>
</head>
<body>
</body>
</html>
上面的例子是针对纯html的,但如果您可以使用php,那么通过$_GET['url']
:获取querystring参数会更方便
<html>
<head>
<script>
setTimeout(function() {
location.replace('<?=$_GET['URL']?>');
}, 5000);
</script>
</head>
<body>
</body>
</html>