0

If I click a button from page A, the browser will redirect to page B. In page B if I click a another button again it redirects to Page A. Here I used window.location.href to redirect the new page.

eg:window.location.href="http:\\localhost:12345\index2.html"

Is any other alternative way to redirect next page. I don't want to use windows.location

Update:

If I use windows.location the url which I come from is stored in document.reffer. For security purposes I don't want to allow to store the url.

freedomn-m
  • 27,664
  • 8
  • 35
  • 57
CheckMyPost_045
  • 103
  • 2
  • 3
  • 14

6 Answers6

6

Location assign() Method

You may use this method example :-

function myFunction() {
    location.assign("https://www.google.co.in");
 }
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<!DOCTYPE html>
    <html>
    <body>
    <button onclick="myFunction()">Load new document</button>
    </body>
    </html>
Aman Kumar
  • 4,533
  • 3
  • 18
  • 40
4

You can also use

window.location.replace("http://someUrl.com");

replace() does not keep the originating page in the session history.

Ayush Sharma
  • 2,057
  • 15
  • 25
1

Using $location in angularjs : See the documentation https://docs.angularjs.org/api/ng/service/$location

georgeawg
  • 48,608
  • 13
  • 72
  • 95
0
$url =$('<a/>')
$url.attr('href',"http://google.com");
$url[0].click()

You can try this.

Arshpreet Wadehra
  • 993
  • 2
  • 9
  • 23
0

You can use location.assign() for redirect another page.

location.assign("https://www.facebook.com/");
georgeawg
  • 48,608
  • 13
  • 72
  • 95
Neeraj Pathak
  • 759
  • 4
  • 13
  • Keep in mind that `location.assign` is subject to same-origin-policy and will throw a security exception if the page is not from the same location. See [MDN Web API Reference - window.location.assign](https://developer.mozilla.org/en-US/docs/Web/API/Location/assign). – georgeawg Feb 11 '20 at 20:27
-1

why not use <a>. what you only to do is give it a class like button.

Boywus
  • 11