PDA

View Full Version : Applying external links to Twitter feed



bassa
02-08-2011, 09:34 AM
Hey!

I've got a small Twitter script running that displays the 3 latest Twitter feeds on my website, but the links within the Twitter feed open in the same window.

I would like to change this behavior to make the Twitter links open in a new window.

How do I do this?


Cheers,
Bassa

bassa
02-08-2011, 09:39 AM
Sorry! Here's the JavaScript:


<script type="text/javascript">
<!--//--><![CDATA[//><!--
$(document).ready(function() {
$("#twitter-box").getTwitter({
userName: "hudplejedk",
numTweets: 3,
loaderText: "Henter seneste tweets...",
slideIn: true,
showHeading: false,
headingText: "Seneste tweets",
showProfileLink: true
});
});
//--><!]]>
</script>


Cheers,
Bassa

azoomer
02-08-2011, 10:17 PM
You can try something like this


<script type="text/javascript">
jQuery(document).ready(function($){
$('#twitter_update_list a[href^="http://"]')
.attr("target", "_blank");
});
</script>

or


<script type="text/javascript">
jQuery(document).ready(function($){
$('#twitter-box a[href^="http://"]')
.attr("target", "_blank");
});
</script>

You may have to tweak it a bit, but it should work, hopefully!

edit: You should probably place it below the twitter scripts

Maybe you can do the same with the facebook links

bassa
02-09-2011, 07:15 AM
I tried this with both of your scripts:


<script type="text/javascript">
<!--//--><![CDATA[//><!--
$(document).ready(function() {
$("#twitter-box").getTwitter({
userName: "hudplejedk",
numTweets: 3,
loaderText: "Henter seneste tweets...",
slideIn: true,
showHeading: false,
headingText: "Seneste tweets",
showProfileLink: true
});
});
//--><!]]>
</script>

<script type="text/javascript">
jQuery(document).ready(function($){
$('#twitter-box a[href^="http://"]')
.attr("target", "_blank");
});
</script>


But unfortunately, none of them seemed to have an effect on the Twitter links.

I was unsure whether you wanted me to place it in the body or the head, so I tried both places with both scripts, but alas, to no avail.


Cheers,
Bassa

azoomer
02-09-2011, 07:49 AM
Hi, maybe you could try this first


<script type="text/javascript">
jQuery(document).ready(function($){
$('a[href^="http://"]')
.attr("target", "_blank");
});
</script>

It should change all the link on the page to open in an external window. If it works you could narrow it down later( google jquery selectors). There could be problems with the loading order so it may be best to place it as far down as possible, even just before the closing body tag. You may want to experiment with a downloaded copy of your page. And get firebug (http://getfirebug.com/) add on where you can see the changes in the dom

bassa
02-09-2011, 08:21 AM
It sort of worked. It made all links open externally, although the links inside the Twitter's ul#twitter_update_list div id still wont open in external links.

The link in the profile bottom (http://www.twitter.com/hudplejedk) also opens externally.


Cheers,
Bassa

azoomer
02-09-2011, 11:52 AM
The only thing I can think of is to try the window load function instead, it should wait with the execution of the script until everything else is loaded


<script type="text/javascript">
$(window).load(function(){
$('#twitter-box a[href^="http://"]')
.attr("target", "_blank");
});
</script>

bassa
02-09-2011, 12:03 PM
Works like a charm. Thanks, dude! ;)


Cheers,
Bassa