HTML Location assign( ) 方法
HTML Location assign() 方法在不替换文档历史记录中的当前 HTML 文档的 URL 的情况下,加载一个新的 HTML 文档。
语法
以下为语法 −
location.assign(URL)
让我们来看一个 HTML Location assign() 方法的示例−
示例
<!DOCTYPE html>
<html>
<style>
body {
color: #000;
height: 100vh;
background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) no-repeat;
text-align: center;
}
.btn {
background: #db133a;
border: none;
height: 2rem;
border-radius: 20px;
width: 330px;
display: block;
color: #fff;
outline: none;
cursor: pointer;
margin: 1rem auto;
}
</style>
<body>
<h1>HTML Location assign() Method Demo</h1>
<button class="btn" onclick="display()">Load Tutorialspoint</button>
<script>
function display() {
location.assign("https://tutorialspoint.com/");
}
</script>
</body>
</html>输出

点击“加载 Tutorialspoint”按钮,在当前文档中加载教程点文档−

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP