1

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.

2 Answers 2

1

You could redirect using window.location.href :

<a target="_blank" href="javascript:window.location.href = createDynamicPubUrl()" >link</a>

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

0

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();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.