Tweet button is sharing the page and not quotes - Problem solved

Tweet button is sharing the page and not quotes - Problem solved
0

#1

Hello fellow campers,

Can anyone offer a little help please. I have a tweet button that is linking to and sharing the page rather than the quotes and I’m a little stuck on how to fix this.

Any suggestions appreciated.

Thanks.

link to pen here https://codepen.io/osania/pen/mAYZVx


#2

I think this post could help you:

You should use web intents instead


#3

Thanks for your help. I’ll check out the links and see how I get on. :thumbsup:


#4

Hi @zsoltime,

Thanks for your suggestions and help the other day, with a little help I manged to sort the problem :thumbsup:, however I have another issue you might be able to help with.

I have appeneded an initial quote to my /< p >/ element that I’d also like users to be able to tweet before clicking on the get quote button.

How can I include this as part of the tweet function I already have? I have a feeling I should be using an if/else statement in there somewhere but unsure how to go about it.

I did create another function to do this, but thinking about the D.R.Y principle reminded me there must be a better way.

Any help or suggestions please.

Thanks in advance.


#5

And you’re right. :slight_smile:

The problem is that your tweet button’s event listener is inside your ‘next quote’ button’s event listener. So, you have to click on that button first to attach the click event to you tweet button. Try to move it outside of that block.

A few other things… I’ve noticed you used jQuery, and although I haven’t used it in the last few years, I think append() is to add nodes/DOM elements and you should use a simple .text() to add your first quote. And I’d also swap the .html()s with .text()s, unless you get an HMTL string in response from the API.

Oh, and if you already use it, you can use jQuery in your tweet() function, instead of vanilla JS.


#6

@zsoltime,

Okay, thank you. :slight_smile: I didn’t spot it was inside the other event listener. I’ll try the above and let you know how I get on. :thumbsup: You have been really helpful.


#7

@zsoltime, Works perfectly. :slight_smile: :sunny: :thumbsup: