Js 跳转页面和打开新窗口的方法

185 篇文章 0 订阅
32 篇文章 0 订阅
  • window.open(‘要跳转的网址’):打开新页面 打开新窗口,默认是_blank

  • window.close():关闭使用JS创建的窗口,某些平台不能关闭

  • window.history.go(1):历史记录窗口

    • back:向后跳转一个页面

    • go:可以指定跳转,正数向前跳,负数向后跳

  • window.location.href=‘要跳转的网址’:  在本窗口刷新打开

    • href:指定当前窗口的url,修改它可以直接实现页面跳转

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        
        <button οnclick="qq()">我要去qq</button>
        <button οnclick="xin()">我要去新浪</button>
        <a href="https://www.baidu.com/" target="_blank">百度一下吧</a>
    </body>
    <script>
        function qq(){
            window.open('http://www.qq.com/')
        }
        function xin(){
            window.location.href="https://www.sina.com.cn/"         
        }
        
    </script>
</html> 

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值