Getting a new page AND a blocked pop-up

Right now I’m getting a working new page for the “tweet quote” but I’m also getting a blocked pop-up. Can someone take a look at my code and tell me whats wrong? or tell me how to tell whats wrong?

The problem is that you’re creating two tweets. One is using the intent API in an anchor tag

 <a class="btn btn-default" href="https://twitter.com/intent/tweet?text=Hello%20world" id="tweetQuote" target="_blank"><i class="fa fa-twitter" aria-hidden="true"></i> Tweet</a>

The other, using window.open

window.open("https://twitter.com/intent/tweet?text="+quoteToTweet)

I’m willing to bet that window.open is being blocked by whichever ad-blocking extension you’re using in your browser. Using the anchor tag is my preferred way, so I suggest changing your code such that the anchor tag contains the text you want to tweet rather than using the pure JavaScript solution.

Thanks for the reply :slight_smile:. It was actually the anchor that was causing the blocked popup so I just removed the href.
But since the anchor is your preferred way, how would one go about changing my window.open to an anchor? I can’t figure out how to add the +quoteToTweet.

href is just an attribute on the anchor tag, so you can use jQuery’s attr method.

$('myLink').attr('href', 'https://some.link')

That link is just a string, so you already have the code to add your quote.

Thanks again!
Changed:

window.open("https://twitter.com/intent/tweet?text="+quoteToTweet);

to

$("#tweetQuote").attr("href", "https://twitter.com/intent/tweet?text="+quoteToTweet);

Works great! I think…:worried:

1 Like

I just tested your updated pen on the latest Safari, Chrome, and Firefox, all of which use ad blockers. It worked fine for me. If you’re having insurmountable trouble on your end, window.open will have the same effect and is fine for the project. Just keep in mind that it’s not going to be the best idea for production-ready apps. :thumbsup:

Much love :heart_eyes: