-3

I am on

www.foo.com

how to call javascript or jquery to navigate to

www.foo.com/site1

or if I am on www.foo.com/site1 to go on

www.foo.com/site1/site2
Yair Nevet
  • 12,725
  • 14
  • 66
  • 108
ThanksBro
  • 911
  • 1
  • 7
  • 20

3 Answers3

1
window.location.href = window.location.href + "/site1"

I suppose this would work.

Bram Vanroy
  • 27,032
  • 24
  • 137
  • 239
1

to get inside site1 from outside

window.location.href="site1/";

to get inside site1/site2 if you are inside site1

 window.location.href="site2/";

to get inside site1/site2 directly if you are "outside"

window.location.href="site1/site2/";

to get out of site1 if you are inside site1

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

to get out of site1/site2 if you are inside site1/site2

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

to get out of site1a if you are inside site1a and into site1b (at same level)

window.location.href="../site1b/";

Of course you do not need javascript for this if you use links like <a href="../site1b/">GO</a> to click.

Using just window.location=.. works too (has even broader support) and even location=.. (you can omit "window.", but I wouldn't do it for clarity and maybe compatibility)

Javascript: Setting location.href versus location

I used all paths with trailing "/", being folders, to avoid automatic redirects from "site1" to "site1/" (slightly slower).

Community
  • 1
  • 1
FrancescoMM
  • 2,845
  • 1
  • 18
  • 29
0

This will trigger it

window.location.href="url/goes/here";

jayaguilar
  • 182
  • 6