JS页面跳转大全

所谓的js页面跳转就是利用javascript对打开的页面URL进行跳转,如我们打开的是A页面,通过javascript脚本就会跳转到B页面。

目前很多垃圾站经常用js跳转将正常页面跳转到广告页面,当然也有一些网站为了追求吸引人的视觉效果,把一些栏目链接做成js链接,但这是一个比较严重的蜘蛛陷阱,无论是SEO人员还是网站设计人员应当尽力避免。

很多站长在制作网站的时候,为了某种展示或SEO优化的目的,常常需要利用js跳转效果,所以对于一个站长或SEO来说,熟练的掌握或使用js技术,已成为一门必学的技能了。

在我这么多年做SEO的过程中,也收集和使用了很多的js代码,今天我就跟大家分享一些常用的js页面跳转代码,希望能对大家有所帮助。

一、常规的JS页面跳转代码

1、在原来的窗体中直接跳转用

[removed]
    [removed].href = "http://www.example.com";
[removed]

2、在新窗体中打开页面用

[removed]
    window.open("http://www.example.com");
[removed]

3、JS页面跳转参数的注解

[removed]
    // 参数解释:
    // 第2种:在指定窗口打开
    window.open("http://www.example.com", "_blank");
    
    // 第3种:在新窗口打开,指定窗口大小和位置
    window.open("http://www.example.com", "newwindow", "height=100,width=400,top=0,left=0,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no");
    
    // 第4种:返回上一页
    window.history.back(-1);
    
    // 第5种:关闭当前窗口
    window.close();
[removed]

三、页面停留指定时间再跳转(如3秒)

<meta http-equiv="refresh" content="3;url=http://www.example.com">

[removed]
    setTimeout(function() {
        [removed].href = "http://www.example.com";
    }, 3000);
[removed]

四、根据访客来源跳转的JS代码

1、JS判断来路代码

[removed]
    if (document.referrer.indexOf("baidu.com") > -1 || document.referrer.indexOf("google.com") > -1) {
        // 来自搜索引擎,跳转到首页
        [removed].href = "http://www.example.com/";
    }
[removed]

2、JS直接跳转代码

[removed]
    [removed].href = "http://www.example.com/";
[removed]

3、ASP跳转代码判断来路

<%
    if instr(Request.ServerVariables("http_referer"),"www.baidu.com")>0 then
        response.redirect("http://www.mahaixiang.cn/")
    end if
%>

4、ASP直接跳转

<%
    response.redirect("http://www.mahaixiang.cn/")
%>

五、页面跳出框架

[removed]
    if (top.location != self.location) {
        top.location = self.location;
    }
[removed]

六、返回上一页

[removed]
    history.go(-1); // 返回上一页
    // 或者
    history.back(); // 返回上一页
[removed]

总结

虽然目前有的搜索引擎技术已经能够得到javascript脚本上的链接,甚至能执行脚本并跟踪链接,但对于一些权重比较低的网站,搜索引擎觉得没有必要,不会浪费精力去抓取分析,不过,对于实现网站的某种特效,还是有很大帮助的。

以上就是常用的JS页面跳转代码大全,包括:

  • [removed].href - 在当前窗口跳转
  • window.open() - 在新窗口打开
  • window.history.back() - 返回上一页
  • setTimeout + location - 延时跳转
  • document.referrer - 判断访客来源
  • top.location - 跳出框架

在实际开发中,应根据需求选择合适的跳转方式,避免滥用js跳转影响SEO优化。

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部