js如何实现页面跳转(大全)

一、总结

一句话总结:

1、location的href属性:

js跳转主要是通过window的location对象的href属性,因为location对象本来就是表示的浏览器窗口window的location,那肯定就是这个决定网页的url。

2、open方法

3、history对象的三个方法

4、location的assign方法

1、js跳转的本质是什么?

解答:浏览器对象窗口location(url)的改变,

2、js中的window的location对象和网页url相同么?

解答:其实可以看做是一回事,都是指的网页的网址。

3、js跳转常用来做哪些事情(两件)?

解答:a、广告跳转。 b、做链接的效果。

4、js跳转用到的是哪个对象的哪个属性?

解答:肯定是location对象的href属性。

5、js跳转主要的几种方法?

解答:location的href属性,open方法,hostory对象,location的assign方法

6、页面停留指定时间再跳转怎么实现?

解答:函数加timeout定时器实现。

<script type="text/javascript">
  function jumurl(){
  window.location.href = 'http://www.mahaixiang.cn/';
  }
  setTimeout(jumurl,3000);
</script>

7、解释一下top.location.href='http://www.mahaixiang.cn/';这个语句?

解答:页面跳出框架。

8、location和框架(iframe)配合可以生产各种位置的广告。这句话对么?

解答:对的。上面是广告下面是站群的代码:document.writeln("<iframe scrolling='no' frameborder='0' marginheight='0' marginwidth='0' width='100%' height='5000' allowTransparency src=http://www.mahaixiang.cn/></iframe>");

9、document的write方法和writeIn方法一般是干嘛的?

解答:向document(页面)里面写入东西的啊。
 

二、js如何实现页面跳转(大全)

所谓的js页面跳转就是利用javesrcipt对打开的页面ULR进行跳转,如我们打开的是A页面,通过javsrcipt脚本就会跳转到B页面。
目前很多垃圾站经常用js跳转将正常页面跳转到广告页面,当然也有一些网站为了追求吸引人的视觉效果,把一些栏目链接做成js链接,但这是一个比较严重的蜘蛛陷阱,无论是SEO人员还是网站设计人员应当尽力避免。
很多站长在制作网站的时候,为了某种展示或SEO优化的目的,常常需要利用js跳转效果,所以对于一个站长或SEO来说,熟练的掌握或使用js技术(具体可查看马海祥博客《JavaScript是什么?JavaScript功能有哪些》的相关介绍),已成为一门必学的技能了。
在我这么多年做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代码

第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>

第3种:这个方法是只针对IE的

<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.mahaixiang.cn/';
  }
  setTimeout(jumurl,3000);
  </script>

四、根据访客来源跳转的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.mahaixiang.cn/";
  </script>

2、JS直接跳转代码

<script LANGUAGE="Javascript">
  location.href="http://www.mahaixiang.cn/";
  </script>

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/")
  %>

五、广告与网站页面一起的JS代码

1、上面是广告下面是站群的代码

document.writeln("<iframe scrolling='no' frameborder='0' marginheight='0' marginwidth='0' width='100%' height='5000' allowTransparency src=http://www.mahaixiang.cn/></iframe>");

2、全部覆盖的代码

document.write("</iframe><iframe src='http://www.mahaixiang.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){}

六、页面跳出框架

<script type="text/javascript">
  top.location.href='http://www.mahaixiang.cn/';
  </script>

七、返回上一页

<script type="text/javascript">
  window.history.back(-1);
  </script>
点评:
虽然目前有的搜索引擎技术已经能够得到javescipt脚本上的链接,甚至能执行脚本并跟踪链接,但对于一些权重比较低的网站,搜索引擎觉得没有必要,不会浪费精力去抓取分析,不过,对于实现网站的某种特效,还是有很大帮助的。

参考:

JS页面跳转大全 - cyy_13 - 博客园
https://www.cnblogs.com/cyy-13/p/5775344.html

三、测试题-简答题

1、js跳转的本质是什么?

解答:浏览器对象窗口location(url)的改变,

2、js中的window的location对象和网页url相同么?

解答:其实可以看做是一回事,都是指的网页的网址。

3、js跳转常用来做哪些事情(两件)?

解答:a、广告跳转。 b、做链接的效果。

4、js跳转用到的是哪个对象的哪个属性?

解答:肯定是location对象的href属性。

5、js跳转主要的几种方法?

解答:location的href属性,open方法,hostory对象,location的assign方法

6、页面停留指定时间再跳转怎么实现?

解答:函数加timeout定时器实现。

<script type="text/javascript">
  function jumurl(){
  window.location.href = 'http://www.mahaixiang.cn/';
  }
  setTimeout(jumurl,3000);
</script>

7、解释一下top.location.href='http://www.mahaixiang.cn/';这个语句?

解答:页面跳出框架。

8、location和框架(iframe)配合可以生产各种位置的广告。这句话对么?

解答:对的。上面是广告下面是站群的代码:document.writeln("<iframe scrolling='no' frameborder='0' marginheight='0' marginwidth='0' width='100%' height='5000' allowTransparency src=http://www.mahaixiang.cn/></iframe>");

9、document的write方法和writeIn方法一般是干嘛的?

解答:向document(页面)里面写入东西的啊。
 
 
 
 
 
 
 
 
 
 

js如何实现页面跳转(大全)的更多相关文章

  1. js关闭当前页面跳转新页面

    页面代码: <p class="info"><span style="font-weight: bold">所属项目:</span ...

  2. JS页面跳转大全

    所谓的js页面跳转就是利用javesrcipt对打开的页面ULR进行跳转,如我们打开的是A页面,通过javsrcipt脚本就会跳转到B页面.目前很多垃圾站经常用js跳转将正常页面跳转到广告页面,当然也 ...

  3. JS打开新页面跳转

      有时候使用js进行页面跳转,想使用 a 标签中 target="_blank" 形式,跳转打开一个新的页面. 可以使用以下脚本,创建一个 a标签,然后模拟点击操作. 代码如下: ...

  4. js中实现页面跳转

    1.在本页中跳转到指定页面 1.window.location.href方式    <script language="javascript" type="text ...

  5. js中实现页面跳转(返回前一页、后一页)

    一:JS 重载页面,本地刷新,返回上一页 代码如下: <a href="javascript:history.go(-1)">返回上一页</a> <a ...

  6. PHP JS HTML ASP页面跳转代码 延时跳转代码 返回到上一界面并刷新 JS弹出指定大小的新窗口

    1.PHP延时跳转代码 //跳转到浏览界面 header("Refresh:1;url=machine_list.php"); //不延时 <?php header(&quo ...

  7. js实现静态页面跳转传参

    最近有个项目: 存静态web服务,一个新闻页面列表出所有新闻摘要信息,然后通过点击新闻详情访问到该新闻的详情页面: 新闻展示的页面通过ajax请求接口获取到新闻的摘要信息,预计想通过id的方式访问到新 ...

  8. JS禁止WEB页面鼠标事件大全

    <!--禁止鼠标右键代码-->:<noscript><ifra:<scriptlanguage=javas:<!--:if(window.Event):doc ...

  9. PHP JS HTML ASP页面跳转代码 延时跳转代码

    1.PHP延时跳转代码 //跳转到浏览界面 header("Refresh:1;url=machine_list.php"); //不延时 <?php header(&quo ...

随机推荐

  1. System and method for controlling switching between VMM and VM using enabling value of VMM timer indicator and VMM timer value having a specified time

    In one embodiment, a method includes transitioning control to a virtual machine (VM) from a virtual ...

  2. [NPM] Publish npm packages using npm publish

    In this lesson we will publish our package. We will first add a prepublish script that runs our buil ...

  3. caffe 在 windows 下的配置(scripts\build_win.cmd)

    官网配置文档见:GitHub - BVLC/caffe at windows 1. windows 设置 requirements: visual studio 2013/2015 CMake > ...

  4. (JavaScript基础向)sort()方法里的排序函数的理解

    比较常见的解释可以看这里:js的sort()方法,这篇博客写得挺好的,一般的应用的理解已经足够了. 但是如果要活用sort()方法里面的参数——也就是排序函数的话,可能就比较难理解了. 然后我就总结出 ...

  5. 【Codeforces Round #447 (Div. 2) C】Marco and GCD Sequence

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 把gcd(a[1..n])放在输入的n个数之间. [代码] /* 1.Shoud it use long long ? 2.Have ...

  6. 2017.1-TOP5 Android开源库

    Colorful (Github) Colorful简单实用,通过这个开源库可以通过编码的方式来改变应用的主题,不再需要定义不同的style dependencies { compile 'com.g ...

  7. 最短路算法详解(Dijkstra/SPFA/Floyd)

    新的整理版本版的地址见我新博客 http://www.hrwhisper.me/?p=1952 一.Dijkstra Dijkstra单源最短路算法,即计算从起点出发到每个点的最短路.所以Dijkst ...

  8. XAMPP简介

    XAMPP是一款开源.免费的网络服务器软件,经过简单安装后,就可以在个人电脑上搭建服务器环境.本文为大家介绍Windows中安装XAMPP(Apache+Mysql+PHP)及使用方法及其相关问题的总 ...

  9. TransE论文剩余部分

    4.3链接预測 表3:链接预測结果.不同方法的性能. 整体结果 表3显示了全部数据集全部方法的比較. 与预期结果一致,经过过滤设置的结果具有较低的平均排名和较高的hits@10,相信在链接预測方面对各 ...

  10. Qt5 UI信号、槽自动连接的控件重名大坑(UI生成的槽函数存在一个隐患,即控件重名。对很复杂的控件,不要在 designer 里做提升,而是等到程序启动后,再动态创建,可以避免很多问题)

    对Qt5稍有熟悉的童鞋都知道信号.槽的自动连接机制.该机制使得qt designer 设计的UI中包含的控件,可以不通过显式connect,直接和cpp中的相应槽相关联.该机制的详细文章见 http: ...