0

I have a hidden link and a button. I want when users click on the button they will go to the link. Why I'm not just show the link so users can click through the link because I don't want users see the link that appear at the bottom of browser.

<a id="stack" href="http://stackoverflow.com/"></a>
<button id="goTo">Stackoverflow</button>

Is it possible?

1
  • 2
    I like to know what URL I'm going to before I click on a link. Why don't you want your users to know? Commented Sep 24, 2014 at 23:22

2 Answers 2

1

Maybe like this :

$(document).ready(function(){
    $("#goTo").on('click',function(e){
        e.preventDefault();
        window.location = $("#stack").attr('href');
    });
});
Sign up to request clarification or add additional context in comments.

4 Comments

Thak you for the answer. But when I click the button the browser load the same page.
It loads a new page with the url in the href of the a#stack so if you change this href it will change the destination
Yes, I see at the bottom of the browser waiting for stackoverflow... after I click the button but I still on the same page. CodePen
Yes it's because on codepen the rendering is made in an iframe on an other domain and you can't reload the parent window in JS from an iframe because of security issue (if you check your console you'll see a message about it when you click)
0

Add simple jquery to relay the click on the button. You can leave the a link out.

$("#goTo").click(function(){
 window.location = "http://stackoverflow.com/";
}

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.