This code (with HTTPS protocol), successfully opens https://www.google.com.
<script>
function openInNewTab() {
var url = 'https://www.google.com';
var win = window.open(url, '_blank');
win.focus();
}
</script>
<div onclick="openInNewTab();">OPEN LINK ON A NEW WINDOW</div>
But when I use this code (without HTTP protocol), it opens https://www.example.com/www.google.com instead.
<script>
function openInNewTab() {
var url = 'www.google.com';
var win = window.open(url, '_blank');
win.focus();
}
</script>
<div onclick="openInNewTab();">OPEN LINK ON A NEW WINDOW</div>
Is there a way to use Javascript to open an external website without HTTPS protocol?
//www.google.com- then the protocol will depend on the protocol of the page making the request (http or https)