CheckMyPost_045
CheckMyPost_045

Reputation: 103

How to redirect without using window.location

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.

Upvotes: 0

Views: 28681

Answers (6)

Neeraj Pathak
Neeraj Pathak

Reputation: 759

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

location.assign("https://www.facebook.com/");

Upvotes: 0

Kévin Blot
Kévin Blot

Reputation: 41

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

Upvotes: 1

Aman Kumar
Aman Kumar

Reputation: 4547

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>

Upvotes: 5

Boywus
Boywus

Reputation: 11

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

Upvotes: -1

Arshpreet Wadehra
Arshpreet Wadehra

Reputation: 1023

$url =$('<a/>')
$url.attr('href',"http://google.com");
$url[0].click()

You can try this.

Upvotes: 0

Ayush Sharma
Ayush Sharma

Reputation: 2107

You can also use

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

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

Upvotes: 4

Related Questions