Home >Web Front-end >Front-end Q&A >How to refresh the page in JavaScript

How to refresh the page in JavaScript

藏色散人
藏色散人Original
2021-07-03 09:53:383042browse

Methods for refreshing the page in JavaScript: 1. Refresh the current document through the reload() method; 2. Replace the current document with a new document through the replace() method.

How to refresh the page in JavaScript

The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.

How to refresh the page in JavaScript?

js Refresh the current page

js Refresh the current page method:

Method 1: reload() method

## The #reload() method is used to refresh the current document.

The reload() method is similar to the refresh page button on your browser.

location.reload();

Method 2: replace() method

replace() method can replace the current document with a new document. .

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
<script>
function replaceDoc()
{
    window.location.replace("http://www.runoob.com")
}
</script>
</head>
<body>
<input type="button" value="载入新文档替换当前页面" onclick="replaceDoc()">
</body>
</html>

Recommended study: "

javascript Advanced Tutorial"

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

Statement:
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