javascript - How to get/set current page URL (which works across space-time-browsers-versions) -


i want get/set url of current page upon event.

it seems there more 1 approach doing mentioned in questions/answers below.

using jquery

get url - $(location).attr('href'); set url - $(location).attr('href',url); 

using javascript

get url - myvar = window.location.href; set url - window.location.href = "http://stackoverflow.com"; 

which approach works across space-time-browsers-versions?

get current url in javascript?

how redirect webpage in javascript/jquery?

i don't see need use jquery this. following work fine in browsers:

window.location.href = "http://stackoverflow.com"; 

or more simply:

location.href = "http://stackoverflow.com";