Links opening in new windows

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Ianardo
Regular
Posts: 114
Joined: Sun Nov 28, 2004 3:02 pm
Location: Hastings, U.K.
Contact:

Links opening in new windows

Post by Ianardo »

Any idea how I can make all external links open in new windows other than editing each link with a target:"_blank" ?

Cheers
Ian
75% of people make up three quarters of the World's population!
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Links opening in new windows

Post by garvinhicking »

Hi!

I think there are javascripts that do this.

BUT: How to open links and windows should be a browser issue. The user should decide how he wants that, and tell his browser to adapt to this. I'm really a big opponent of target_blank.

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Ianardo
Regular
Posts: 114
Joined: Sun Nov 28, 2004 3:02 pm
Location: Hastings, U.K.
Contact:

Re: Links opening in new windows

Post by Ianardo »

garvinhicking wrote:I'm really a big opponent of target_blank.
Ooh! I'm not! I hate it when someone navigates away from one of my sites just because they have clicked a link. I want them to stay! And buy or commission stuff :wink:
75% of people make up three quarters of the World's population!
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Links opening in new windows

Post by garvinhicking »

Hi!

If they WANT to stay, they would open your links in a new window via Shift/Middle-Mouse click.

Don't think about what your visitor can do for you, think about what YOU can do FOR your Visitor! Then they will stay on your site on their own.

It's all about giving power to people. I'm a strong fighter for this concept, which is why I develop Serendipity. :-)

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
nation-x
Regular
Posts: 5
Joined: Tue Jul 18, 2006 2:27 pm

Post by nation-x »

add and HTML nugget

put <BASE target="_blank">
nation-x
Regular
Posts: 5
Joined: Tue Jul 18, 2006 2:27 pm

Re: Links opening in new windows

Post by nation-x »

garvinhicking wrote:If they WANT to stay, they would open your links in a new window via Shift/Middle-Mouse click.
You give surfers too much credit. The average surfer has no idea they can do that.
Ianardo
Regular
Posts: 114
Joined: Sun Nov 28, 2004 3:02 pm
Location: Hastings, U.K.
Contact:

Post by Ianardo »

I tend to agree with nation-x. We get so close to computers sometimes that we forget that 99.9% of computer users only turn them on once a week to look at email.
add and HTML nugget

put <BASE target="_blank">
I don't quite understand. Does this go in a head nugget do you mean? Surely an ordinary html nugget couldn't affect the whole site.
75% of people make up three quarters of the World's population!
nation-x
Regular
Posts: 5
Joined: Tue Jul 18, 2006 2:27 pm

Post by nation-x »

I added it at the top of the content.
dk70
Regular
Posts: 19
Joined: Sat Aug 13, 2005 9:53 am

Post by dk70 »

Ianardo
Regular
Posts: 114
Joined: Sun Nov 28, 2004 3:02 pm
Location: Hastings, U.K.
Contact:

Post by Ianardo »

Nation-x - I tried yours but then every link opens a new page - neat, but a bit excessive.

dk70 - I'm afraid I can't get that Javascript to work anywhere without breaking the site. It needs to be in the <body> so i've tried content, entries and index.tpl's

Where did you use it?
75% of people make up three quarters of the World's population!
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

Javascript should work in the index.tpl. However, since the index.tpl is parsed by Smarty, and both Smarty and Javascript assign special meaning to the curly braces "{}", there's going to be a conflict.

Smarty is going to win, since it goes first -- on the server, whereas Javascript has to wait until the client's browser is ready to execute it.

To slip the braces past Smarty and on to Javascript, you need to convince Smarty to either ignore the braces, or generate them.

Ignoring the braces is the simpler solution. Smarty passes on anything between {literal} tags, thusly:

Code: Select all

{literal}
some_javascript
{
  with(braces);
}
{/literal}
Simple enough: just enclose all your Javascript in {literal} tags.

Generating the braces isn't difficult, just annoying. Smarty will turn any instance of {ldelim} into a left-curly-brace, and any instance of {rdelim} into a right-curly-brace. Thusly:

Code: Select all

some_javascript
{ldelim}
  with(braces);
{rdelim}
Also relatively simple: just replace all occurrences of "{" with {ldelim} and all occurrences of "}" with {rdelim} in your Javascript only.

Finally, you can bypass Smarty altogether and put Javascript directly in your header. Use the "Head Nugget" to put arbitrary HTML (including Javascript or meta tags) in the head of your page output.

When you visit your page, if your Javascript doesn't work as expected, first check the page source. If the script looks like you wanted, there's likely a problem with the script. If it's missing all its braces, you need one of the solutions above.
Judebert
---
Website | Wishlist | PayPal
Ianardo
Regular
Posts: 114
Joined: Sun Nov 28, 2004 3:02 pm
Location: Hastings, U.K.
Contact:

Post by Ianardo »

Brilliant! Worked first time.

Thank you so much Judebert :D :D :D

---added---

This has really got to be the most useful mod I have ever made to any of my Serendipity websites - and so simple! I've already added it to all my client's sites. It makes life so much easier.
Last edited by Ianardo on Wed Jul 26, 2006 3:49 pm, edited 1 time in total.
75% of people make up three quarters of the World's population!
nation-x
Regular
Posts: 5
Joined: Tue Jul 18, 2006 2:27 pm

Re: Links opening in new windows

Post by nation-x »

Ianardo wrote:Any idea how I can make all external links open in new windows other than editing each link with a target:"_blank" ?

Cheers
Ian
well... you did say "all". :)
Ianardo
Regular
Posts: 114
Joined: Sun Nov 28, 2004 3:02 pm
Location: Hastings, U.K.
Contact:

Re: Links opening in new windows

Post by Ianardo »

nation-x wrote:
Ianardo wrote:Any idea how I can make all external links open in new windows other than editing each link with a target:"_blank" ?

Cheers
Ian
well... you did say "all". :)
Naaa, "all external" :D
75% of people make up three quarters of the World's population!
dk70
Regular
Posts: 19
Joined: Sat Aug 13, 2005 9:53 am

Post by dk70 »

I used same head nugget as judebert mentioned.

To add something useful may be try Smart-Cursor if you use Firefox https://addons.mozilla.org/firefox/2771/ Can get same result without extension, just somelines in usercontent.css, but this is easier. Works just fine in Firefox 2.0 Beta - use this if you dont want to edit install file http://users.blueprintit.co.uk/~dave/we ... index.html
Post Reply