Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2006-01-02 20:35:22
- alexandra
- Member
- From: Cologne, Germany
- Registered: 2004-04-02
- Posts: 1,370
External links in an external new window
- external links in an external new window -
Any easy to access javasript around or even a plugin for this?
EDIT: I found this on Justin Frenchs site but it is pretty old… no idea if it still works
Last edited by alexandra (2006-01-02 20:40:47)
Offline
Re: External links in an external new window
I would easily be feasible to create a modified version of zem_link with an optional attribute target
. Would this fulfill your needs?
//w&
Last edited by wet (2006-01-03 05:58:30)
Offline
Re: External links in an external new window
target
is only for frames websites with the appropriate DTD. And we all know frames are evil don’t we ? :) And it’s not strict at all (strict is good, eat strict).
To answer the question, nope there’s no easy way as far as I can tell. A javascript parser may be able to do it (I don’t know enough DOM to tell) ; parsing the whole page against regexp rule (or against a specific class).
Another way to go would be to do this server-side. Hook into the link makers (one in the link manager, one in Textile, one for pages/forms) and either add a class so that a javascript may parse it, or add some inline javascript code to open in a new window.
What is it for ? In 99.9999999% of the cases, opening external pages into a new window is bad idea, bad policiy, and will annoy most visitors. If they want to open it in a new window, they can do it quite easily by themself. They can’t easily do the other way around.
Offline
Re: External links in an external new window
I think Justin’s might work. Will have to try it, that’s what i’ve been looking for.
edit: ok apparently not as i cant find the line line taghandlers.php..
Last edited by KLS (2006-01-03 07:00:57)
Offline
Re: External links in an external new window
I really do not get the notion of those advocating the avoidance of target
in order to adhere to the STRICT doctype while going great lengths and hooking up javascript with special selectors just to trick a JS enabled browser into acting to their liking.
IMHO, if you wanted your site to confirm with the W3C recommendations then do not use target
, neither inside the static HTML code nor by modifying the DOM on the fly. YMMV. At least you shall not forget that these are recommendations, not law, forcing you to think for yourself where you cannot delegate decisions to a higher authority.
“That’s what rules are for, lad. So that you think before you break them.” Terry Pratchet, from “Thief of Time”
Offline
Re: External links in an external new window
I personally feel external links are to be open in external windows as i myself am tired of of pressing cntrl+click to open up links in a new window when they’re supposed to. Anyways, it’s still accessible to those who have javascript turned off right?
Last edited by KLS (2006-01-03 07:03:49)
Offline
Re: External links in an external new window
wet wrote:
I really do not get the notion of those advocating the avoidance oftarget
in order to adhere to the STRICT doctype while going great lengths and hooking up javascript with special selectors just to trick a JS enabled browser into acting to their liking.
Well it’s not my liking. Apart from very specific cases (the TXP tag maker for one – at least until there is some ajax into this) it’s not the webmaster call to open a page into a new window. It’s the user choice. Since we’re having some trouble opening the eyes of some webmasters, we talk on this on two front… the deprecated target attribute, and the policy of not opening new window.
IMHO, if you wanted your site to confirm with the W3C recommendations then do not use
target
, neither inside the static HTML code nor by modifying the DOM on the fly.
It’s not what we are doing. Javascript can open a new window without inserting false target attribute.
YMMV. At least you shall not forget that these are recommendations, not law, forcing you to think for yourself where you cannot delegate decisions to a higher authority.
I don’t, I go way further by talking and – trying to – coding semantic, beside simple validation. Being able to achieve clean XHTML (but clean HTML would be ok too) code is the main strenght of TXP. Each time someone put a messy website out there, it’s more burden to the web. Each time one of those sites is powered by TXP, it’s also a burden on TXP imnsho.
More to the point, if you don’t have a moderm browser, and know how to tweak it, you are bound by the target attribute. You got no choice. With a javascript code to open in a new window, at least you code a little choice. It’s more friendly (well, less unfriendly), still semantic, and a little less a burden.
Offline
Re: External links in an external new window
Understood, thus Justin French’s solution is a bad choice, too.
So I may modify my proposal, regarding Alexandra’s original request, that zem_link might easily inject a onclick="window.open( <URL> );return false;" href="<URL>"
sequence. Usability issues set aside…
Jeremie, what do you consider as “best practice onclick event code”?
Offline
Re: External links in an external new window
A javascript window.open
is the way to go, if someone wants to open a new window. Cleaner than the target
attribute.
But to do it automatically on every external hyperlinks would require more than a hack of Alex’s plugin. Beside, I’m not found of plugins used for core feature. If a new version break the plugin, the website can’t upgrade, and this is a security risk.
Offline
Re: External links in an external new window
Ok two new things on that topic.
First, an elegant solution for all of us : the Padawan website. It has a checkbox (upper right corner for me) labeled “Open external links in new window” and I guess some cookie thing to keep it between pages and sessions. I’m guessing each link is parsed by javascript, and if the correct cookie is found a new.window
statement is added ; or something like it.
Second, there’s a TXP FAQ item on opening new windows. Damn, Alex works fast these days :p
Last edited by Jeremie (2006-01-04 04:42:08)
Offline
#11 2006-01-04 05:07:36
- zem
- Developer Emeritus
- From: Melbourne, Australia
- Registered: 2004-04-08
- Posts: 2,579
Re: External links in an external new window
I suppose you could also use PR Block to add an onClick event to links. If someone wants to nut it out, or provide some other solutions, I’ll add them to the FAQ.
Alex
Offline