开发者

Redirect base url to homepage

开发者 https://www.devze.com 2023-04-06 15:08 出处:网络
I need to find the base url and redirect it to the \'home\' page. Also I need to use relative expressions so that I don\'t have to edit the js file and it could be used in diferent websites.

I need to find the base url and redirect it to the 'home' page. Also I need to use relative expressions so that I don't have to edit the js file and it could be used in diferent websites.

I'm using jqu开发者_JAVA百科ery and so far I have this:

    if (location.host) {
    location.replace((location.host) + '/home');
    }

But is not working... I am new to js and I need help.


You could try this:

window.location.href = "/home";


Maybe you want to do window.location.replace(location.host + '/home'); ?

Also, take a look at this question: How can I make a redirect page in jQuery?


Well, you can just do this :

window.top.location.href = "/home";

It will automatically takes the domain and just adds the specified string and sets it. It works in all the browsers but its good to show an message like

The page will automatically redirect you to http://some.com/url/index.html, if it doesn't then click here.


I realise this is a very old question but maybe someone will stumble across it like I just did.

I'm pretty sure this is the answer the OP wanted:

if (window.location.pathname === '/') {
  window.location.replace('/home');
}
0

精彩评论

暂无评论...
验证码 换一张
取 消