关于javascript跳转与返回和刷新页面

2020-3-1    前端达人

javascript中window.open()与window.location.href的区别

window.open(‘index.html’) 表示新增一个窗口打开 index.html 这个页面,并不刷新

location.href(‘index.html’) 表示在当前窗口重定向到新页面,打开并刷新 index.html 这个页面



window.location 是 window 对象的属性,用来替换当前页,也就是重新定位当前页

而window.open 是 window 对象的方法,是用来打开一个新窗口的函数



// 打开新页面
    // 注意:有些浏览器的安全设置会将window.open()屏蔽,例如避免弹出广告窗
    window.open('./index.html');

    // 在原窗口打开新页面
    window.location.href="./index.html";

    

window.open()详解

window.open ('page.html', 'newwindow', 'height=100, width=400, 
top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=n o, status=no')

参数解释: 三个参数
 window.open 弹出新窗口的命令;
 ‘page.html’ 弹出窗口的文件名;
 ‘newPage’ 弹出窗口的名字(不是文件名),非必须,可用空’'代替;
 height=100 窗口高度;
 width=400 窗口宽度;
 top=0 窗口距离屏幕上方的象素值;
 left=0 窗口距离屏幕左侧的象素值;
 toolbar=no 是否显示工具栏,yes为显示;
 menubar=no 是否显示菜单栏,yes为显示;
 scrollbars=no 是否显示滚动栏,yes为显示;
 resizable=no 是否允许改变窗口大小,yes为允许;
 location=no 是否显示地址栏,yes为允许;
 status=no 是否显示状态栏内的信息(通常是文件已经打开),yes为允许;

常用的js返回与刷新页面
在此用a标签举例



分享本文至:

日历

链接

个人资料

蓝蓝 http://www.lanlanwork.com

存档