javascript window.location 与相对 url

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9910468/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 08:11:35  来源:igfitidea点击:

window.location with relative url

javascriptjquery

提问by Blainer

I am trying to use window.location to redirect to a relative url

我正在尝试使用 window.location 重定向到相对 url

this variable

这个变量

var redirect = $(this).attr('title');

has this value

有这个值

../../000_Movies/_assets/playlist.html

this wont redirect

这不会重定向

window.location = redirect;

回答by Bogdan Emil Mariesan

If you want to redirect to relative pages you should use:

如果你想重定向到相关页面,你应该使用:

 window.location.href = "../../000_Movies/_assets/playlist.html";

回答by ThdK

You can use:

您可以使用:

window.location.href = $(this).attr('title');