Location.assign()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Location.assign()
方法会触发窗口加载并显示指定的 URL 的内容。
如果由于安全原因无法执行跳转,那么会抛出一个 SECURITY_ERROR
类型的 DOMException
。当调用此方法的脚本来源和页面的 Location
对象中定义的来源隶属于不同域的时候,就会抛出上述错误。
如果传入了一个无效的 URL,则会抛出一个 SYNTAX_ERROR
类型的 DOMException
。
语法
location.assign(url);
参数
示例
js
// 跳转到 Location.reload() 这篇文章
document.location.assign(
"https://developer.mozilla.org/zh-CN/docs/Web/API/Location/reload",
);
规范
Specification |
---|
HTML # dom-location-assign-dev |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | server | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
assign |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- Partial support
- Partial support
- No support
- No support
- User must explicitly enable this feature.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
相关内容
- 父级接口
Location
。 - 相似的方法:
Location.replace()
和Location.reload()
。