为什么我跳转总是跳到慕课网错误页面?

来源:8-17 编程练习

慕标1082868

2015-12-27 16:50

<!DOCTYPE html>
<html>
 <head>
  <title>浏览器对象</title>  
  <meta http-equiv="Content-Type" content="text/html; charset=gkb"/>
  <style type="text/css">
#opt{
   font-weight:bold;/*设置字体加粗*/
}
</style>
 </head>
 <body>
  <!--先编写好网页布局-->
  <p id = "opt">
      操作成功
  </p>
  <p>
      5秒后回到主页 <a href="" onClick="goBack()"> 返回</a>
  </p>
 
  <script type="text/javascript">  
 
   //获取显示秒数的元素,通过定时器来更改秒数。
   var i = setTimeout("goHome()",5000);
   //通过window的location和history对象来控制网页的跳转。
   function goBack() {
       history.back(-1);
   }
   function goHome() {
       window.open(location.hostname);
   }
   //document.write(location.hostname);
 </script> 
</body>
</html>

五秒后跳转如下图:

http://img.mukewang.com/567fa63b0001074912670745.jpg

写回答 关注

1回答

  • 宇师
    2015-12-27 17:34:30
    已采纳

    window.open('http://'+location.hostname);

    慕标1082...

    非常感谢!

    2015-12-27 17:59:05

    共 1 条回复 >

JavaScript进阶篇

本课程从如何插入JS代码开始,带您进入网页动态交互世界

468788 学习 · 22582 问题

查看课程

相似问题