Results 1 to 8 of 8

Thread: Applying external links to Twitter feed

  1. #1
    Join Date
    Apr 2008
    Posts
    109
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Applying external links to Twitter feed

    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

  2. #2
    Join Date
    Apr 2008
    Posts
    109
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    Sorry! Here's the JavaScript:

    Code:
    <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

  3. #3
    Join Date
    Oct 2009
    Posts
    845
    Thanks
    14
    Thanked 189 Times in 188 Posts

    Default

    You can try something like this
    Code:
    <script type="text/javascript"> 
    jQuery(document).ready(function($){
    $('#twitter_update_list a[href^="http://"]')
      .attr("target", "_blank");
    });
    </script>
    or
    Code:
    <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
    Last edited by azoomer; 02-08-2011 at 10:39 PM.

  4. #4
    Join Date
    Apr 2008
    Posts
    109
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    I tried this with both of your scripts:

    Code:
    <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

  5. #5
    Join Date
    Oct 2009
    Posts
    845
    Thanks
    14
    Thanked 189 Times in 188 Posts

    Default

    Hi, maybe you could try this first
    Code:
    <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 add on where you can see the changes in the dom

  6. #6
    Join Date
    Apr 2008
    Posts
    109
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    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

  7. #7
    Join Date
    Oct 2009
    Posts
    845
    Thanks
    14
    Thanked 189 Times in 188 Posts

    Default

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

  8. The Following User Says Thank You to azoomer For This Useful Post:

    bassa (02-09-2011)

  9. #8
    Join Date
    Apr 2008
    Posts
    109
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    Works like a charm. Thanks, dude!


    Cheers,
    Bassa

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •