Sign Up! Login: Password: New User? Forgot? Support
Top Mods!
Wowhead Search
by sonofsamedi
Digital Clock
by Wolfar15
Admin Forums
Welcome to the GuildPortal Help Community! These forums are for admin-to-admin help.
Available Forums
Forums : Voodoo Tech and Scripter's Den of Scriptniquity > Default Link behavior in Forum Posts
Corganno (Guild Admin) 7/30/2011 8:38 AM EST : Default Link behavior in Forum Posts
Corganno
Posts: 584
Zomgawsh Poster


Is there a way to change the default hyperlink behavior for forum posts?  I'd love to make it have all links open up in a new window, unless a different selection is made by the poster.

I've found where you can change this, per link, when posting, but by default it just uses the same window and no one ever sets it manually. 

I had been using some java script (in the 
Custom Javascript/jQuery - Additional Functions window) to do it in the past, but suddenly it's not working anymore. Any ideas? 

This was the code that I was using:

*Edit: Removed the coding I was using from forum post, Mottie's code is much better*


TopBottom

Mottie (MVP) 8/1/2011 8:04 PM EST : RE: Default Link behavior in Forum Posts
GuildPortal MVP
Mottie
Posts: 3883
Zomgawsh Poster

Hi Corganno! Try this:


Open External Forum Links in a New Tab

This script searches for any link inside the forum posts and makes it open in a new tab/window. Additionally, it adds a css class name of "external-link" so you can style the link differently. In the example below, it adds an external link icon after the link.

Code
Ideally, add the following code to a Free Form Text/HTML widget on the Forums Page. But you could also add it to the Footer HTML (Control Panel > Custom HTML & Script > Footer Area).
<style>
a.external-link {
  background: url(
http://i201.photobucket.com/albums/aa236/Mottie1/testsite/icons/forum_link.gif) top right no-repeat;
  padding-right:
20px;
}
</style>
<script>
$(function(){
  var guild = 'GuildID=' + getGroupId();
  $('.MessageBodyCell1 a').each(function(){
    if (this.href && !this.href.match(guild)){
      $(this).addClass('external-link').attr('target','_blank');
    }
  });
});
</script>
Customizing
  • Change or remove the background image by modifying the image url in orange. Adjust the padding-right in red to fit the image.
  • If you want to modify the link color, do it as follows:
     .external-link:link { color: #ffcc00; }
     .external-link:hover { color:
    #ffffff; }
     .external-link:visited, .external-link:active { color:
    #ff8800; }
    Modify the link colors in blue as desired.
TopBottom

Admins Online
There are   members online.
So-and-so has logged on!
%title%
%message%