自动将某人重定向到另一个网页的最佳方法是什么? [英] What's the best way to automatically redirect someone to another webpage?

查看:18
本文介绍了自动将某人重定向到另一个网页的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从未学过 JavaScript,但我想这是一个相当简单的问题.只是想知道现在最推荐哪种方法.

I've never learnt JavaScript, but I imagine this is quite a simple problem. Just wanted to know which method is most advised these days.

推荐答案

// use this to avoid redirects when a user clicks "back" in their browser
window.location.replace('http://somewhereelse.com');

// use this to redirect, a back button call will trigger the redirection again
window.location.href = "http://somewhereelse.com";

// given for completeness, essentially an alias to window.location.href
window.location = "http://somewhereelse.com";

编辑:看起来发布更好答案的用户已经离开了,我已经在此处合并了他的答案.

edit: looks like the user who posted the better answer has left SO, i've consolidated his answers here.

这篇关于自动将某人重定向到另一个网页的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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