The current URL in jQuery can be obtained by using the 'href' property of the Location object which contains information about the current URL. The 'href' property returns a string with the full URL of the current page.
To clone a div and change its id with JavaScript, we can use the cloneNode method on the div. Then we can set the id property of the cloned element to set the ID. to add the div.
//As an HTTP redirect (back button will not work )
window.location.replace("http://www.google.com");
//like if you click on a link (it will be saved in the session history,
//so the back button will work as expected)
window.location.href = "http://www.google.com";
why not using?
location.href='http://www.example.com';
<!DOCTYPE html>
<html>
<head>
<script>
function goToURL() {
location.href = 'http://google.it';
}
</script>
</head>
<body>
<a href="javascript:void(0)" onclick="goToURL(); return false;">Go To URL</a>
</body>
</html>
window.location is just what you need. Other thing you can do is to create anchor element and simulate click on it
$("<a href='your url'></a>").click();
Actually, you have to use the anchor # to play with this. If you reverse engineer the Gmail url system, you'll find
https://mail.google.com/mail/u/0/#inbox
https://mail.google.com/mail/u/0/#inbox?compose=new
Everything after # is the part your want to load in your page, then you just have to chose where to load it.
By the way, using document.location by adding a #something won't refresh your page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With