I was trying to get the current URL and replace it with something else. But my code does not work if x = document.URL, but for x = "String" everything works perfectly
function test(){
var x = document.URL
var url = window.location.toString();
window.location = url.replace( x , 'whatever');
}
test();
Thank you for helping me out
document.URLis equal towindow.location.toString(), so your code will actually dodocument.location = "whatever"replacedoes. developer.mozilla.org/en-US/docs/JavaScript/Reference/…document.URLis a simple string.So I can change the URL even when it change- not clear what do you mean here. You can do that without any x var.document.location = "whatever", it will go to google.com/whatever, but if u put the entire URL:document.location = "http://www.whatever.com", only then it will replace the whole URL. Hope this helps. :)