亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Home Web Front-end JS Tutorial js method to refresh page

js method to refresh page

Mar 31, 2018 pm 04:55 PM
javascript js Encyclopedia

This article introduces several methods to refresh the current page using js, including reload method, replace method, automatic refresh method, etc. Friends in need can refer to it

How to refresh the current page? With js you can do anything.

1, reload method, this method forces the browser to refresh the current page.
Syntax: location.reload([bForceGet])
Parameters: bForceGet, optional parameter, default is false, retrieve the current page from the client cache. true, then use GET method to get the latest page from the server, which is equivalent to the client clicking F5 ("Refresh")

2, replace method, which replaces the current cache in the history by specifying the URL (client-side) project, so after using the replace method, you cannot access the replaced URL through "forward" and "back".
Syntax: location.replace(URL)
Usually use: location.reload() or history.go(0) to do it.
This method is similar to the client point F5 to refresh the page, so when the page method="post", a "webpage expired" prompt will appear.
Because of the security protection mechanism of Session.
When the location.reload() method is called, the aspx page already exists in the server memory, so it must be IsPostback.
If there is such an application: The page needs to be reloaded, which means that the page is expected to be re-created on the server side, and the expectation is Not IsPostback.
Here, location.replace() can complete this task. The replaced page is regenerated on the server every time.
Code: location.replace(location.href);

Return and refresh the page:

location.replace(document.referrer);
document .referrer //The URL of the previous page

Do not use history.go(-1), or history.back(); to return and refresh the page. These two methods will not refresh the page.
Attachment:

Several ways to refresh the page using Javascript:


Copy code The code is as follows :

1,history.go(0) 
2,location.reload() 
3,location=location 
4,location.assign(location) 
5,document.execCommand('Refresh') 
6,window.navigate(location) 
7,location.replace(location) 
8,document.URL=location.href

How to automatically refresh the page:
1, the page automatically refreshes: add the following code to the area


Copy code The code is as follows:

<meta http-equiv="refresh" content="20">

The 20 refers to refreshing the page every 20 seconds.
2, the page automatically jumps: add the following code In the area


##Copy code The code is as follows:

<meta http-equiv="refresh" content="20;url=http://www.jb51.net">

The 20 refers to jumping after 20 seconds Go to http://www.jb51.net page


3, the page will automatically refresh the js version


Copy code The code is as follows:

<script language="JavaScript">
function myrefresh()
{
   window.location.reload();
}
setTimeout(&#39;myrefresh()&#39;,1000); //指定1秒刷新一次
</script>

4, JS refresh frame script statement


Copy code The code is as follows :

//刷新包含該框架的頁面用   
<script language=JavaScript>
   parent.location.reload();
</script>
//子窗口刷新父窗口
<script language=JavaScript>
    self.opener.location.reload();
</script>
( 或 <a href="javascript:opener.location.reload()">刷新</a>   )
//刷新另一個框架的頁面用   
<script language=JavaScript>
   parent.另一FrameID.location.reload();
</script>

If you want to refresh when the window is closed or you want to refresh when the window is opened, just call the following statement in .


Copy code The code is as follows:

<body onload="opener.location.reload()"> 開窗時刷新
<body onUnload="opener.location.reload()"> 關閉時刷新
<script language="javascript">
window.opener.document.location.reload()
</script>


First, let’s look at a simple example:

The following takes three pages named frame.html, top.html, and bottom.html as an example to explain how to do it.
frame.html consists of two pages: top (top.html) and bottom (bottom.html). The code is as follows:

##Copy code

The code is as follows:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<HTML> 
<HEAD> 
<TITLE> frame </TITLE> 
</HEAD> 
<frameset rows="50%,50%"> 
<frame name=top src="top.html"> 
<frame name=bottom src="bottom.html"> 
</frameset> 
</HTML>

Now assume that top.html (i.e., the page above) has seven buttons to refresh bottom.html (i.e., the page below). You can use the following seven statements. Which one is better for you to decide? Done. The code of the

top.html page is as follows:


Copy code

The code is as follows:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<HTML> 
<HEAD> 
<TITLE> top.html </TITLE> 
</HEAD> 
<BODY> 
<input type=button value="刷新1" onclick="window.parent.frames[1].location.reload()"><br> 
<input type=button value="刷新2" onclick="window.parent.frames.bottom.location.reload()"><br> 
<input type=button value="刷新3" onclick="window.parent.frames[&#39;bottom&#39;].location.reload()"><br> 
<input type=button value="刷新4" onclick="window.parent.frames.item(1).location.reload()"><br> 
<input type=button value="刷新5" onclick="window.parent.frames.item(&#39;bottom&#39;).location.reload()"><br> 
<input type=button value="刷新6" onclick="window.parent.bottom.location.reload()"><br> 
<input type=button value="刷新7" onclick="window.parent[&#39;bottom&#39;].location.reload()"><br> 
</BODY> 
</HTML>

The following is the source code of the bottom.html page, In order to prove that the page below has indeed been refreshed, a dialog box pops up after the page is loaded.



Copy code

The code is as follows:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<HTML> 
<HEAD> 
<TITLE> bottom.html </TITLE> 
</HEAD> 
<BODY onload="alert(&#39;我被加載了!&#39;)"> 
<h1>This is the content in bottom.html.</h1> 
</BODY> 
</HTML>

Explain:



Copy code

code show as below:


1.window指代的是當前頁面,例如對于此例它指的是top.html頁面。
2.parent指的是當前頁面的父頁面,也就是包含它的框架頁面。例如對于此例它指的是framedemo.html。
3.frames是window對象,是一個數(shù)組。代表著該框架內所有子頁面。
4.item是方法。返回數(shù)組里面的元素。
5.如果子頁面也是個框架頁面,里面還是其它的子頁面,那么上面的有些方法可能不行。
附:
Javascript刷新頁面的幾種方法:
1 history.go(0)
2 location.reload()
3 location=location
4 location.assign(location)
5 document.execCommand('Refresh')
6 window.navigate(location)
7 location.replace(location)
8 document.URL=location.href


二、自動刷新頁面
1.頁面自動刷新:把如下代碼加入區(qū)域中
<meta http-equiv="refresh" content="20">
其中20指每隔20秒刷新一次頁面.
2.頁面自動跳轉:把如下代碼加入區(qū)域中
<meta http-equiv="refresh" content="20;url=http://www.jb51.net">
其中20指隔20秒后跳轉到http://www.jb51.net頁面
3.頁面自動刷新js版


[Ctrl+A 全選 注:如需引入外部Js需刷新才能執(zhí)行]


三、java在寫Servler,Action等程序時,要操作返回頁面的話(如談出了窗口,操作完成以后,關閉當前頁面,刷新父頁面)

復制代碼 代碼如下:

1 PrintWriter out = response.getWriter(); 
2 out.write("<script type=\"text/javascript\">"); 
3 ////子窗口刷新父窗口 
4 out.write("self.opener.location.reload();"); 
5 //關閉窗口 
6 out.write("window.opener=null;"); 
7 out.write("window.close();"); 
8 out.write("</script>");

四、JS刷新框架的腳本語句
1.如何刷新包含該框架的頁面用

復制代碼 代碼如下:

<script language=JavaScript> 
parent.location.reload(); 
</script>


2.子窗口刷新父窗口

復制代碼 代碼如下:

<script language=JavaScript> 
self.opener.location.reload(); 
</script>

3.如何刷新另一個框架的頁面用 (上面的實例以說明了)

復制代碼 代碼如下:

語句1. window.parent.frames[1].location.reload(); 
語句2. window.parent.frames.bottom.location.reload(); 
語句3. window.parent.frames["bottom"].location.reload(); 
語句4. window.parent.frames.item(1).location.reload(); 
語句5. window.parent.frames.item(&#39;bottom&#39;).location.reload(); 
語句6. window.parent.bottom.location.reload(); 
語句7. window.parent[&#39;bottom&#39;].location.reload();

4.如果想關閉窗口時刷新或者想開窗時刷新的話,在中調用以下語句即可。

<body onload="opener.location.reload()"> 
開窗時刷新 
<body onUnload="opener.location.reload()"> 
關閉時刷新

復制代碼 代碼如下:

<script language="javascript"> 
window.opener.document.location.reload() 
</script>

相關推薦:

js刷新頁面方法大全

The above is the detailed content of js method to refresh page. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1488
72
Comprehensive review of i5-13490F processor specifications and performance Comprehensive review of i5-13490F processor specifications and performance Jan 02, 2024 pm 06:12 PM

The i5-13490F is a CPU only sold in mainland China. It has just been launched recently. Its performance is slightly improved compared to the 13400F. It performs very well in games and brings us low power consumption and high performance. Comprehensive evaluation of i5-13490F processor parameters: 1. The performance of the i5-13490F processor is improved by 0.2GHz compared to the i5-13400F; the level 3 cache is increased to 24MB. 2. The improvement of single-core performance and level-3 cache will help gamers in terms of performance. 3. At 2K resolution, i5-13490F performs slightly better in games than i5-13400F. i7-13490F Parameter Evaluation Complete Performance Benchmarks: CPU-z’s benchmark scores reached single

WebSocket and JavaScript: key technologies for implementing real-time monitoring systems WebSocket and JavaScript: key technologies for implementing real-time monitoring systems Dec 17, 2023 pm 05:30 PM

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

Recommended: Excellent JS open source face detection and recognition project Recommended: Excellent JS open source face detection and recognition project Apr 03, 2024 am 11:55 AM

Face detection and recognition technology is already a relatively mature and widely used technology. Currently, the most widely used Internet application language is JS. Implementing face detection and recognition on the Web front-end has advantages and disadvantages compared to back-end face recognition. Advantages include reducing network interaction and real-time recognition, which greatly shortens user waiting time and improves user experience; disadvantages include: being limited by model size, the accuracy is also limited. How to use js to implement face detection on the web? In order to implement face recognition on the Web, you need to be familiar with related programming languages ??and technologies, such as JavaScript, HTML, CSS, WebRTC, etc. At the same time, you also need to master relevant computer vision and artificial intelligence technologies. It is worth noting that due to the design of the Web side

Essential tools for stock analysis: Learn the steps to draw candle charts with PHP and JS Essential tools for stock analysis: Learn the steps to draw candle charts with PHP and JS Dec 17, 2023 pm 06:55 PM

Essential tools for stock analysis: Learn the steps to draw candle charts in PHP and JS. Specific code examples are required. With the rapid development of the Internet and technology, stock trading has become one of the important ways for many investors. Stock analysis is an important part of investor decision-making, and candle charts are widely used in technical analysis. Learning how to draw candle charts using PHP and JS will provide investors with more intuitive information to help them make better decisions. A candlestick chart is a technical chart that displays stock prices in the form of candlesticks. It shows the stock price

JavaScript and WebSocket: Building an efficient real-time weather forecasting system JavaScript and WebSocket: Building an efficient real-time weather forecasting system Dec 17, 2023 pm 05:13 PM

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

Simple JavaScript Tutorial: How to Get HTTP Status Code Simple JavaScript Tutorial: How to Get HTTP Status Code Jan 05, 2024 pm 06:08 PM

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

PHP and JS Development Tips: Master the Method of Drawing Stock Candle Charts PHP and JS Development Tips: Master the Method of Drawing Stock Candle Charts Dec 18, 2023 pm 03:39 PM

With the rapid development of Internet finance, stock investment has become the choice of more and more people. In stock trading, candle charts are a commonly used technical analysis method. It can show the changing trend of stock prices and help investors make more accurate decisions. This article will introduce the development skills of PHP and JS, lead readers to understand how to draw stock candle charts, and provide specific code examples. 1. Understanding Stock Candle Charts Before introducing how to draw stock candle charts, we first need to understand what a candle chart is. Candlestick charts were developed by the Japanese

How to get HTTP status code in JavaScript the easy way How to get HTTP status code in JavaScript the easy way Jan 05, 2024 pm 01:37 PM

Introduction to the method of obtaining HTTP status code in JavaScript: In front-end development, we often need to deal with the interaction with the back-end interface, and HTTP status code is a very important part of it. Understanding and obtaining HTTP status codes helps us better handle the data returned by the interface. This article will introduce how to use JavaScript to obtain HTTP status codes and provide specific code examples. 1. What is HTTP status code? HTTP status code means that when the browser initiates a request to the server, the service

See all articles