Page 1 of 2

Links opening in new windows

Posted: Wed Jul 05, 2006 11:26 am
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

Re: Links opening in new windows

Posted: Wed Jul 05, 2006 11:44 am
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

Re: Links opening in new windows

Posted: Wed Jul 05, 2006 12:03 pm
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:

Re: Links opening in new windows

Posted: Wed Jul 05, 2006 1:10 pm
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

Posted: Wed Jul 19, 2006 6:46 pm
by nation-x
add and HTML nugget

put <BASE target="_blank">

Re: Links opening in new windows

Posted: Wed Jul 19, 2006 6:48 pm
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.

Posted: Wed Jul 19, 2006 7:00 pm
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.

Posted: Wed Jul 19, 2006 7:14 pm
by nation-x
I added it at the top of the content.

Posted: Thu Jul 20, 2006 1:18 am
by dk70

Posted: Wed Jul 26, 2006 11:03 am
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?

Posted: Wed Jul 26, 2006 3:11 pm
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.

Posted: Wed Jul 26, 2006 3:36 pm
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.

Re: Links opening in new windows

Posted: Wed Jul 26, 2006 3:37 pm
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". :)

Re: Links opening in new windows

Posted: Wed Jul 26, 2006 3:50 pm
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

Posted: Wed Jul 26, 2006 9:44 pm
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