Search

Hello, my customer begs me to have links opened in a new window/tab. He stores text in a textarea, which contains Markdown+SmartyPants support. With a nice extension an link can be inserted by clicking on a button. Though, when the link is shown on the front-end, the target to open it is the current window. I would need to insert the attribute..

target="_blank"

.. into the tag of the link.

According to a existing discussion ( http://getsymphony.com/discuss/thread/761/#position-9 ) it is possible to match the tag, but I have problems with replacing this tag withing the text and finally display the text with the modified link.

Can anyone help me? Thanks in advance.

target=”_blank”

What HTML doctype are you using on your frontend? There is no target attribute in XHTML so it will invalidate your markup unles you’re using HTML 4.01.

I recommend using a JavaScript solution e.g.

Use jQuery to Open All External Links in a New Window

Although personally I’d suggest investing your time in convincing your client that opening windows in a new browser without asking would be against the will of your user base ;-)

Alright, just changed from XHTML 1.0 strict to transitional as the target attribute in anchors is allowed there.

The jQuery solution just fits me right I guess, thanks for the hint.

You are right, it’s not the proper way of opening links. But the client is so far apart of web technology that he probably would not understand this matter. Though, it’s wort a try :)

You should also point out to him that it’s considered a bit usability no-no by both users and browser. Most modern browser will block his links as a matter of course. It also takes the power away from the user.

Most modern browser will block his links as a matter of course

Block @target links? Which browsers?

Alternately, you can use a modified version of my Alternate Text Attribute Splitter. It will let you do put whatever attributes you want into the alt attribute of images and other objects, so I’m sure you can modify it to support the a element’s title attribute as well.

Block @target links? Which browsers?

I’m guessing you mean target="_blank" links. Most browsers. Chrome, Firefox and Safari all do and I was under the impression that IE7 and IE8 both do as well now.

Besides, as I said, one of the other reasons to avoid this is because it removes choice from the user. Users who are more tech savvy, and thus more likely to know about and use multiple tabs or windows, can choose to do so by right-clicking. Those who don’t know how to use these features at will tend to be confused when they’re forced upon them.

Jakob Nielsen has done a number of usability studies on it and concluded that the practice of forcing a link to open in a new window or a new tab is detrimental to the user experience and usability of a site.

(Time to put on my Devil’s Advocate hat…)

That’s odd, this week I’ve had 2 different clients request that I add target=”_blank”, (both for what I think were valid reasons) and they are working fine in FF and Safari.

Their thinking is (and I tend to agree) that users that don’t know how to use contextual menus would be even more confused when they loose the site they were on that had a link to an external site. These were some very specific instances, where the UI goals were not intending users to leave the linking site.

In the pre-tab day I would agree it is a UI problem, but with tabs much less so.

I suppose it’s moot, since it really is pretty old school & deprecated (even though I hear from the An Event Apart HTML5 talks that being deprecated is deprecated, hurray for progress). Guess I’ll throw it in the bin along with b, i and the underscore hack.

My experience has lead me to believe that in the tab days it’s even more an issue.

Consider this use case: Someone goes to a public library and opens up Firefox. They’re used to IE at home and don’t really use tabs. They click on a link and it opens in a new tab. They look over the site and for whatever reason decide it’s not what they want so they click the back button. Nothing happens. Where did the site go? They close the window. Nope, it wasn’t a new window. Well that’s annoying.

I actually spend a lot of my time at a local library (my mother runs it) so I get to see and help people who aren’t technologically inclined. Those tend to be the people who need things to be more simple or else they get confused. To these people the web is a weird and alien thing that they think they will never and can never understand so when something goes other than expected they are more likely to just walk away assuming it’s something they did.

More tech-savvy users, however, are perfectly happy to poke and prod and mess around. They know about tabs and windows, they know their contextual menus. For these people, forcing links to open in new tabs or windows is fine because they understand what’s happened. It’s the other people you need to worry about.

Besides, the way I see it is if a user clicks on a link and leaves your web site they are doing so by choice. If they choose to go back they have the back button, which is a user convention every web user is familiar with. If, however, they have no plans on returning to your site then they don’t have to close another window or tab.

Personally, I’ve never seen a situation where using a new window or tab was advantageous to the user. I normally see it done on sites that don’t want you to leave because they’re trying to sell you something and they think that if it’s harder for you to leave you’ll just give in. (This is never, ever works. Ever.)

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details