您的位置:首页 > 运维架构 > 网站架构

网站跳转的几种实现方法

2016-08-21 17:49 246 查看
网站跳转的几种实现方法

一、初级使用方法

使用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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: