bodacydo
bodacydo

Reputation: 79349

What is the correct way to preserve protocol (http or https) when doing a redirect through "window.location.href = ..."?

I'm redirecting a user on a website from one page to another by using:

window.location.href = "http://page.com/new_url";

But problem is that sometimes website is accessed from HTTP, but sometimes from HTTPS.

How do I make the redirect work and preserve the protocol?

Upvotes: 2

Views: 174

Answers (1)

SLaks
SLaks

Reputation: 887459

You want a protocol-relative URL:

//example.com/path

Upvotes: 8

Related Questions