0

I wish to simulate clicking on a link and redirecting using js, i do this with:

window.location 

But how can I keep the current path:

mysite.com/article/page

And go to:

mysite.com/article/page/some-js-var

I know I can do:

window.href+'/'+myVar

Is there a better way?

panthro
  • 22,779
  • 66
  • 183
  • 324
  • 1
    HTML 5 history API is the way, [see this](http://stackoverflow.com/questions/5210034/history-pushstate) – Saqueib Feb 12 '15 at 11:59
  • I know you didnt ask but if you become to solution make your personal router on the client-side then i think you probably should look at backbone or angular js – Smile0ff Feb 12 '15 at 12:02
  • You want to preserve the link in the address bar and want to show the user a different page? – void Feb 12 '15 at 12:06
  • I just want to get the link that's in the address bar – panthro Feb 12 '15 at 12:07

1 Answers1

0

This gives you the exact url the user is on:

document.location.href
void
  • 36,090
  • 8
  • 62
  • 107