Reputation: 131
I am trying to redirect to a hostname which is coming as part of request after appending https:// to this.
<a target="_blank" href="javascript:createDynamicPubUrl();" >
Below is the function to create a url by appending hostname with protocol(https) :
function createDynamicPubUrl() {
publisherHostName = document.getElementById('hostname').value;
var pubUrl ;
var protocol = 'https://';
pubUrl = protocol+publisherHostName;
return pubUrl;
}
Instead of redirecting to pubUrl
it is printing the pubUrl
on the webpage.
Upvotes: 1
Views: 87
Reputation: 67505
You could redirect using window.location.href
:
<a target="_blank" href="javascript:window.location.href = createDynamicPubUrl()" >link</a>
Hope this helps.
Upvotes: 1
Reputation: 1202
Redirecting to HTTPS is better done on the server side. If however you want to redirect to the HTTPS version on the client side, you can use window.location.href
:
function createDynamicPubUrl() {
publisherHostName = document.getElementById('hostname').value;
var pubUrl ;
var protocol = 'https://';
pubUrl = protocol+publisherHostName;
return pubUrl;
}
window.location.href = createDynamicPubUrl();
Upvotes: 0