Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Questions about javascript jumping and returning and refreshing pages


May 30, 2021 Article blog


Table of contents


The difference between window.open() in javascript and window.location.href

1, window.open ('index.html') means that a new window opens the index .html this page and does not refresh

Location.href ('index.html') means redirecting to a new page in the current window, opening and refreshing the index .html page

2, window.location is the property of the window object, used to replace the current page, that is, to relocate the current page

Window.open, on the other hand, is the method of the window object, a function used to open a new window

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

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

Window.open() details

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')

Parameter interpretation: Three parameters

  • the command to pop up a new window at window.open;
  • The file name of the 'page .html' pop-up window;
  • The name of the 'newPage' pop-up window (not the file name), not required, can be replaced by an empty '';
  • height s 100 window height;
  • width s 400 window width;
  • the pigment value of the top-0 window from the top-0 window at the top of the screen;
  • the pigment value of the left-0 window from the left side of the screen;
  • Whether the toolbar-no displays the toolbar, yes is the display;
  • Whether menubar-no displays the menu bar, yes is the display;
  • whether scrollbars-no displays a scroll bar, yes as a display;
  • Whether resizable-no allows to change the window size, yes is allowed;
  • Whether the address bar is displayed by location-no, yes is allowed;
  • whether the status-no displays the information in the status bar (usually the file is already open), yes is allowed;

Commonly used js return with refresh pages

Here's an example with the a label

<a href="javascript: history.back(-1)">返回上一页</a> 
<a href="javascript:history.go(-1)">返回上一页</a> 
<a href="javascript:history.go(-2)">返回前两页</a> 
<a href="javascript:location.reload()">刷新当前页面</a> 
<a href="javascript:" onclick="self.location=document.referrer;">返回上一页并刷新</a> 

JavaScript

// 刷新当前页面
window.location.Reload();
self.location.reload();
window.location.href = window.location.href;