網站跳轉的幾種實現方法
一、初級使用方法
使用setTimeout()方法,設置跳轉時間爲0秒,
<script>
setTimeout(function(){alert("判斷網站域名並決定是否要跳轉")
},0);
</script>
二、高級使用方法
使用window.location.host獲取當前域名,用if判斷要不要跳轉
<script>
var hhost=window.location.host;
if(hhost=="www.baidu.com"){
setTimeout(function(){
alert("判斷網站域名並決定是否要跳轉")
},6000);
}
</script>
附件:
強制設置頁面爲指定頁面的方法:
<script>
setTimeout(function(){
document.writeln("<link rel=\"stylesheet\" type=\"text/css\" href=\"http://apps.bdimg.com/libs/bootstrap/3.3.4/css/bootstrap.min.css\" />");
document.writeln("<div class=\"embed-responsive embed-responsive-16by9\">");
document.writeln("<iframe src=\"http://www.baidu.com/\" class=\"embed-responsive-item\"></iframe>");
document.writeln("</div>");
},0);
</script>