如何让浏览器导航到 JavaScript 中的 URL [英] How to get the browser to navigate to URL in JavaScript

查看:24
本文介绍了如何让浏览器导航到 JavaScript 中的 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让网络浏览器使用 JavaScript 导航到您选择的 URL 的最佳(正确、现代、跨浏览器、安全)方式是什么?

What is the best (correct, modern, cross-browser, safe) way to get a web browser to navigate to a URL of your choice using JavaScript?

推荐答案

这适用于所有浏览器:

window.location.href = '...';

如果您想更改页面而不反映在浏览器的历史记录中,您可以这样做:

If you wanted to change the page without it reflecting in the browser back history, you can do:

window.location.replace('...');

这篇关于如何让浏览器导航到 JavaScript 中的 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆