Can't make my buttons link to an external website

Can't make my buttons link to an external website
0.0 0

#1

I have the following code, but when I click the buttons it loads a white page:

<button class="btn btn-block btn-primary" onclick="window.location.href='https://www.facebook.com'"><i class="fa fa-facebook left">acebook</i></button>

#2

opps here is the code —acebook


#3

I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.


#4

Thank you, but I don’t see the cleaned up version of my mess :slight_smile:


#5

I edited your initial post. You should see your code under: [quote=“AGFarooq, post:1, topic:99238”]
I have the following code, but when I click the buttons it loads a white page:
[/quote]


#6

Ah I get it, I thought you had solved my link problems. Thanks for the other tip though, very useful.


#7

Do you use CodePen or something similar? In that case window.location.href doesn’t work.


#8

I am using Codepen and it seems like a few things don’t work in it. But the challenge asks for a button to link to your social media. Not sure how to get around it then.


#9

You can use <a href="[your-facebook-link-here]" target="_blank">CLICK HERE FOR MY FACEBOOK</a>

The target="_blank" makes the link open in a new tab. If you want you can put your button (or any other HTML element) inside the <a></a>.


#10

Awesome. thanks it worked.