Location assign()Method

Location 对象参考手册Location Object

Definition and Usage

The assign() method loads a new document.

Syntax

location.assign(URL)


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the assign() method.


Example

Example

Use assign() to load a new document:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<script>
function newDoc(){
    window.location.assign("http://www.example.com")
}
</script>
</head>
<body>

<input type="button" value="Load new document" onclick="newDoc()">

</body>
</html>

Try it Yourself »


Location 对象参考手册Location Object Other Extensions