重定向到JavaScript中的相对URL [英] Redirecting to a relative URL in JavaScript

查看:123
本文介绍了重定向到JavaScript中的相对URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了问题:
我想通过JavaScript重定向到上面的目录。
我的代码:

I have a problem: I want to redirect via JavaScript to a directory above. My code:

location.href = (location.href).substr(0, (location.href).lastIndexOf('folder'));

网址如下所示:


example.com/path/folder/index.php?file=abc&test=123&lol=cool

example.com/path/folder/index.php?file=abc&test=123&lol=cool

重定向会影响到这一点:

The redirect affect just this:


example.com/path/&test=123&lol=cool

example.com/path/&test=123&lol=cool

但想要这个:


example.com / path /

example.com/path/

我怎么能这样做?

推荐答案

您可以进行相对重定向:

You can do a relative redirect:

window.location.href = '../'; //one level up

window.location.href = '/path'; //relative to domain

这篇关于重定向到JavaScript中的相对URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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