Convert URLs to HTTPS via Javascript

I want to convert the current url to https version with javascript. How can i do this?

Example: http://www.abc.comhttps://www.abc.com

+3
source share
2 answers
window.location = window.location.href.replace(/^http:/, 'https:');
+10
source

If you know that your http url starts with "http: //", then it is as simple as:

var httpsUrl = "https" + httpUrl.substring(4);
+2
source

Source: https://habr.com/ru/post/1775102/


All Articles