homepage Welcome to WebmasterWorld Guest from 184.72.72.182
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
What's the javascript for target=" blank"?
internetheaven




msg:4125489
 7:38 pm on May 1, 2010 (gmt 0)

Using this script in the head for processing ad links on the page:

<script type="text/javascript"> function clickTrack() { window.location="http://www.example.com" } </script>

the ads are surrounded by:

<span onmouseover="this.style.cursor='pointer'" onclick="clickTrack(); return false;" onMouseDown="clickTrack(); return false;">

How do I make that open in a new window?

Thanks
Mike

 

caribguy




msg:4125513
 8:21 pm on May 1, 2010 (gmt 0)

window.open('http://www.example.com','_blank')

lavazza




msg:4125593
 12:06 am on May 2, 2010 (gmt 0)

Jakob Nielsen's Alertbox, May 30, 1999:
The Top Ten Web Design Mistakes of 1999
[useit.com]
2. Opening New Browser Windows
Opening up new browser windows is like a vacuum cleaner sales person who starts a visit by emptying an ash tray on the customer's carpet. Don't pollute my screen with any more windows, thanks (particularly since current operating systems have miserable window management). If I want a new window, I will open it myself!

Designers open new browser windows on the theory that it keeps users on their site. But even disregarding the user-hostile message implied in taking over the user's machine, the strategy is self-defeating since it disables the Back button which is the normal way users return to previous sites. Users often don't notice that a new window has opened, especially if they are using a small monitor where the windows are maximized to fill up the screen. So a user who tries to return to the origin will be confused by a grayed out Backbutton.

internetheaven




msg:4126003
 10:19 am on May 3, 2010 (gmt 0)

I totally agree with the sentiment, lavazza, but in this case, the user will be provide four possible providers for the service they have search for on our site. They will most likely go through the first provider's site considerably before deciding they are not suitable and wish to return to our website to try the other three in the same way. "Back" buttons, I did not feel, would be an easy way for them to do this. Opening each service provider in a new window seemed the best option for the user to me.

lavazza




msg:4126365
 8:39 pm on May 3, 2010 (gmt 0)

Before implementing your intended approach, I suggest you test the idea by surveying a cross-section of users

You might be surprised, especially if they are using a variety of media and/or platforms

Anyone who slaps a 'this page is best viewed with Browser X' label on a Web page appears to be yearning for the bad old days, before the Web, when you had very little chance of reading a document written on another computer, another word processor, or another network.
Tim Berners-Lee [w3.org]

TheMadScientist




msg:4130010
 7:35 am on May 10, 2010 (gmt 0)

Don't pollute my screen with any more windows, thanks

Learn to use the tabbed browsing that's present in all major browsers. Thanks!

It's actually starting to annoy me when people DON'T open links in a new window, especially if they run a directory I might want to click more than one link from... Two or 3 pages into a site they link to is way more 'backs' than I want to click as a user. I would rather just close the window (AKA tab in 2010).

lavazza




msg:4130018
 7:46 am on May 10, 2010 (gmt 0)

It's actually starting to annoy me when people DON'T open links in a new window, especially if they run a directory I might want to click more than one link from
Then use a combination of mouse (or similar input device) and UA (e.g browser) that has 'open in a new tab' as the default action for one of the buttons
TheMadScientist




msg:4130033
 8:52 am on May 10, 2010 (gmt 0)

You're citing a source from over a decade ago and the Internet is not stagnant much as it seems some would like to think what once applied should always apply... They didn't even have tabbed browsing then.

(particularly since current operating systems have miserable window management)

Not even close to true today.

Google's gone so far as to convert their results to AJAX and they're already discontinuing support for IE 6... The article you're referring to precedes even IE 5, and if people really don't like it every major browser has a pop-up blocker installed. I think it's time to move past the 1999 idea of the Internet personally.

@ Internetheaven, I think you would be silly to NOT open a new window for people if it makes the overall experience better, and keeps them from having to overuse the back button to return to your site and follow another link, because the Internet is definitely growing up, and most of the people who don't understand how to set a browser to open a new window in a new tab have kids who understand how to set a browser to open a new window in a new tab, and if they don't they probably have a friend who knows, and if it's something they really don't like they'll complain about it and learn how and may even realize pop-ups aren't such a bad thing any more after all.

I used to despise pop-ups, then they invented tabbed browsing and I think they're cool and useful, but don't get me started on pop-unders!

StoutFiles




msg:4130100
 12:59 pm on May 10, 2010 (gmt 0)

Before you all start jumping on the OP for opening a new browser window, you should probably ask WHY he's doing it. In certain situations a new window has to be opened, or a client wants it that way.

caribguy




msg:4130240
 4:36 pm on May 10, 2010 (gmt 0)

@stoutfiles +1 - I remember asking a similar question [webmasterworld.com] and decided to preface it with a disclaimer - just to avoid this type of OT discussions.

A member with several hundred posts under his or her belt should probably be trusted to have considered any usability implications, right? Right? :)

rocknbil




msg:4130273
 5:00 pm on May 10, 2010 (gmt 0)

<span onmouseover="this.style.cursor='pointer'" onclick="clickTrack(); return false;" onMouseDown="clickTrack(); return false;">


Just don't use span, use an anchor. You have a bunch of code there not needed to force the span to do what you want when an anchor does this inherently.

Example [webmasterworld.com] (so the user knows it's a new window - but you will need to remove the target attribute.)

Not mentioned here is the pain of popup blockers, the previous example addresses that as well.

There are very good reasons to use a new window, many times they are not good reasons and indeed invalid, so the original source is STILL spot on. Some things don't change.

It's also interesting that target is coming back in HTML5.

[edited by: rocknbil at 5:04 pm (utc) on May 10, 2010]

Fotiman




msg:4130285
 5:12 pm on May 10, 2010 (gmt 0)

@TheMadScientist, lavazza:
The Jakob Nielson article referenced earlier in this thread was, indeed, from 1999. However, it was updated in 2007 [useit.com] and still included that item as one of the top 10 mistakes. Most of it remained the same, but with this addition:

Links that don't behave as expected undermine users' understanding of their own system. A link should be a simple hypertext reference that replaces the current page with new content. Users hate unwarranted pop-up windows. When they want the destination to appear in a new page, they can use their browser's "open in new window" command -- assuming, of course, that the link is not a piece of code that interferes with the browser’s standard behavior.


In other words, if links are created that don't modify the browser's standard behavior (replace current content with the content of the link), then users have the option of opening the link in the standard way, or opening in a new window/tab. The reverse is not true. If you force a new window/tab, you've taken that control away from the user.

@StoutFiles, caribguy:
Because opening new windows has LONG been established as bad practice, I don't think anyone should be surprised when someone brings up the subject whenever a poster asks how to do it. Having several hundred posts in no way implies any knowledge about usability experience. And doing it because "a client wants it that way" is not a good reason. "The Client" who wants it that way is probably not a usability expert. They hire a developer for their expertise and knowledge, so it's up to the developer to point out that, "hey, this is considered bad practice and let me explain why...".

Demaestro




msg:4130323
 5:42 pm on May 10, 2010 (gmt 0)

Opening up new browser windows is like a vacuum cleaner sales person who starts a visit by emptying an ash tray on the customer's carpet. Don't pollute my screen with any more windows, thanks (particularly since current operating systems have miserable window management). If I want a new window, I will open it myself!


I don't agree with this sentiment.

Many users aren't even savvy enough to upgrade to a modern browser, to expect they know the procedure to open links in a new browser on their own is a huge assumption.

IMO:
PDFs, .xls, .doc should always open in a new window. (or tab)
Offsite links often can open in a new window. (or tab)
Printable receipts should always open in a new window. (In fact I like all my printable pages to open in a new window. I remove nav links and such from my printable pages. Giving someone a dead end page like that in their current browser seems like a really bad idea.)

I set my browser so that new windows open in a new tab instead to protect my screen real estate.

"a client wants it that way" is not a good reason


I think the client wanting it that way is the best reason to do it. Of course it is your duty to explain why it may not be a good idea and to explain both the up and the down side of this practice but if the client wants it and the client is paying then you do it for the client.

Just because it is considered "bad practice", isn't reason to warn people off it everytime it comes up in a thread, there are still plenty of real world use-cases to do this and it not be "bad".

Fotiman




msg:4130329
 5:52 pm on May 10, 2010 (gmt 0)

Well put. I should have clarified that I do feel there are SOME valid cases for opening a new window. My intention, though, was to point out that discussion about this is always valuable.

Demaestro




msg:4130337
 6:01 pm on May 10, 2010 (gmt 0)

discussion about this is always valuable.


I agree 100%, knowledge is power.

System
redhat



msg:4131001
 7:26 pm on May 10, 2010 (gmt 0)

The following 9 messages were cut out by jatar_k.

[edited by: jatar_k at 7:02 pm (utc) on May 11, 2010]

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved