Go Back   SitePoint Forums > Forum Index > Program Your Site > General Development Issues
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
Reply
 
Thread Tools Display Modes
Old Mar 5, 2003, 16:33   #1
Jason Donald
SitePoint Co-Founder
 
Jason Donald's Avatar
 
Join Date: Jun 2000
Location: Melbourne, Victoria, Australia
Posts: 196
New-Window Links in a Standards-Compliant World

This forum thread discusses the article 'New-Window Links in a Standards-Compliant World' by Kevin Yank.

"On the surface, the latest (X)HTML standards seem to frown upon links that open in a new window with target=_blank. But with a little creativity, new-window links can be done in a standards-compliant way, with minimum hassle."
Jason Donald is offline   Reply With Quote
Old Mar 7, 2003, 03:49   #2
1magic
SitePoint Enthusiast
 
1magic's Avatar
 
Join Date: Jan 2002
Posts: 54
Why waste your time?

This is great hint - how to use a JavaScript to open links in new window.

But why waste your time?
Is really standart compliancy so important?
1magic is offline   Reply With Quote
Old Mar 7, 2003, 04:39   #3
Bill Posters
SitePoint Wizard
 
Bill Posters's Avatar
 
Join Date: Dec 2001
Location: UK
Posts: 1,524
http://www.sitepointforums.com/showt...threadid=98703
Bill Posters is offline   Reply With Quote
Old Mar 7, 2003, 14:28   #4
ant1832
SitePoint Addict
 
ant1832's Avatar
 
Join Date: Apr 2002
Location: Tucson, AZ
Posts: 224
But what about people who disable javascript?
ant1832 is offline   Reply With Quote
Old Mar 8, 2003, 03:23   #5
Bill Posters
SitePoint Wizard
 
Bill Posters's Avatar
 
Join Date: Dec 2001
Location: UK
Posts: 1,524
Quote:
Originally Posted by ant1832
But what about people who disable javascript?
Quote:
Originally Posted by Bill Posters
Specifically: http://www.sitepointforums.com/showt...049#post702049
Bill Posters is offline   Reply With Quote
Old Mar 8, 2003, 09:26   #6
ant1832
SitePoint Addict
 
ant1832's Avatar
 
Join Date: Apr 2002
Location: Tucson, AZ
Posts: 224
well that answers it...thanks billl
ant1832 is offline   Reply With Quote
Old May 5, 2003, 09:14   #7
hafrancis
SitePoint Member
 
Join Date: May 2003
Location: Lincoln, MA
Posts: 1
InInteresting technique, Kevin. But how can one specify the size of the new window?
hafrancis is offline   Reply With Quote
Old May 5, 2003, 12:48   #8
vgarcia
☆★☆★
silver trophy
 
vgarcia's Avatar
 
Join Date: Jan 2002
Location: in transition
Posts: 21,481
Quote:
Originally Posted by hafrancis
InInteresting technique, Kevin. But how can one specify the size of the new window?
Code:
<a href="mypage.html" 
onclick="window.open(this.href, 'newWin', 'width=300, height=450');">My
 Link</a>
vgarcia is offline   Reply With Quote
Old May 6, 2003, 16:15   #9
redux
gingham dress, army boots...
silver trophy
 
redux's Avatar
 
Join Date: Apr 2002
Location: Salford / Manchester / UK
Posts: 4,856
Quote:
Originally Posted by vgarcia
Code:
<a href="mypage.html" 
onclick="window.open(this.href, 'newWin', 'width=300, height=450');">My
 Link</a>
i'd add return false as well...

Code:
<a href="mypage.html" 
onclick="window.open(this.href, 'newWin', 'width=300, height=450'); return false;">My
 Link</a>
redux is offline   Reply With Quote
Old May 6, 2003, 16:47   #10
vgarcia
☆★☆★
silver trophy
 
vgarcia's Avatar
 
Join Date: Jan 2002
Location: in transition
Posts: 21,481
Quote:
Originally Posted by redux
i'd add return false as well...

Code:
<a href="mypage.html" 
onclick="window.open(this.href, 'newWin', 'width=300, height=450'); return false;">My
 Link</a>
Uh, yeah, lapse in judgement on my part. Otherwise, the link will open in both the original and the new window. Thanks redux!
vgarcia is offline   Reply With Quote
Old May 16, 2003, 14:06   #11
terts
SitePoint Member
 
Join Date: May 2003
Location: Massachusetts
Posts: 2
How do you call the smallerwindow using the rel="external" script?

I tried to just replace the "_blank" with this code:
* * *anchor.target = OpenWin = this.open(url, "CtrlWindow", "left=0,top=75,height=550,width=500,toolbar=yes,menubar=yes,location=no,scroll bars=yes,resizable=yes");
OpenWin.focus();

We have been using this code for some time now on our site. Problem is we call the script using the onClick attribute, which does not validate in XML transitional 1.0.

any ideas?
Thanks!
Terri
terts is offline   Reply With Quote
Old May 20, 2003, 01:27   #12
Optimum
SitePoint Zealot
 
Optimum's Avatar
 
Join Date: Apr 2003
Location: Miramar
Posts: 123
Keep in mind popups are great to use AT TIMES but more and more people are purchasing or downloading for free, popup blocker software. Eg.

"EarthLink rolled out Pop-Up Blocker in August. EarthLink provided Pop-Up Blocker for free download to its 4.7 million members. The company does not release the number of users who have downloaded the software, estimating only that it is "well into the six figures." "

I think anyway you get it done is fine, its just how much people will be blocking this window that should be a major concern.

People frown on anything they get their minds on. Microwaves were frowned upon once too. Can't make everyone happy.
Optimum is offline   Reply With Quote
Old May 20, 2003, 08:05   #13
terts
SitePoint Member
 
Join Date: May 2003
Location: Massachusetts
Posts: 2
We do not use it as a popup, per se. When someone is going to be leaving our site (outside links), then we open a smaller window so they can navigate on that site. We use this instead of _blank so that the new window does not cover the original window.
terts is offline   Reply With Quote
Old May 20, 2003, 08:33   #14
M. Johansson
Wanna-be Apple nut
silver trophy
 
M. Johansson's Avatar
 
Join Date: Sep 2000
Location: Halmstad, Sweden
Posts: 7,614
Quote:
Originally Posted by 1magic
But why waste your time?
Is really standart compliancy so important?
HEATHEN
M. Johansson is offline   Reply With Quote
Old Jun 15, 2003, 19:15   #15
jadesailor
SitePoint Member
 
jadesailor's Avatar
 
Join Date: Jun 2003
Location: Los Angeles
Posts: 10
I was making a XHTML compliant site and found that _target was not supported.
The solution here is fine, but I got a problem with a form I needed (well, the client "needed") to submit in a new window.
I guess you should do the same thing as with "a" tags but instead check whether is a "form" tag?
I am surprised that this is the only solution to a widely use atribute.
jadesailor is offline   Reply With Quote
Old Jun 16, 2003, 05:41   #16
vgarcia
☆★☆★
silver trophy
 
vgarcia's Avatar
 
Join Date: Jan 2002
Location: in transition
Posts: 21,481
Quote:
Originally Posted by jadesailor
I was making a XHTML compliant site and found that _target was not supported.
The solution here is fine, but I got a problem with a form I needed (well, the client "needed") to submit in a new window.
I guess you should do the same thing as with "a" tags but instead check whether is a "form" tag?
I am surprised that this is the only solution to a widely use atribute.
If you really need the "target" attribute to open links in a new window, then drop down to XHTML Transitional rather than Strict. It's as valid a standard as any still .
vgarcia is offline   Reply With Quote
Old Jun 16, 2003, 05:50   #17
jofa
Sultan of Ping
 
jofa's Avatar
 
Join Date: Mar 2002
Location: Svíþjóð
Posts: 4,101
Quote:
Originally Posted by jadesailor
The solution here is fine, but I got a problem with a form I needed (well, the client "needed") to submit in a new window.
I guess you should do the same thing as with "a" tags but instead check whether is a "form" tag?
I added this to the externalLinks() function:
Code:
	var forms = document.getElementsByTagName("form"); 
	for(var i = 0; i < forms.length; i++) 
	{ 
		var form = forms[i]; 
		if(form.getAttribute("action").substring(0, 4) == "http") 
		{
			form.target = "_blank"; 
		}
	}
Worked for me, because the only forms I want to submit to a new window are the ones with an "external" action, i.e. action begins with "http://..."
jofa is offline   Reply With Quote
Old Jun 16, 2003, 16:58   #18
jadesailor
SitePoint Member
 
jadesailor's Avatar
 
Join Date: Jun 2003
Location: Los Angeles
Posts: 10
Yeah, that's right, the forms I submit to new windows are external http addresses, so this will work!
Thank you
jadesailor is offline   Reply With Quote
Old Jun 23, 2003, 18:14   #19
Ronin SpoilSpot
SitePoint Member
 
Join Date: Jun 2003
Location: Brabrand
Posts: 1
As far as I can see, all the browsers I have available accepts the document.links collection. With it, the code of this article can be made more efficient than with the getElementsByTagName function.

Code:
function setTarget() { 
  var refs = [document.links,document.forms];
  for (var refidx in refs) {
    var collection = refs[refidx];
    for (var i=0;i<collection.length;i++) {
      if (collection[i].ref == "external") {
        collection[i].target="_blank"; 
      } 
    }
  }
}
I prefer using the ref attribute to the class attribute, since the class attribute can contain more than one class name. One can still use CSS selectors to match the external links:
Code:
  *[ref="external"]:after {content:url(external.png);}
Unsurpricingly, attribute selectors don't work in IE, but the rest of us can use them. I have a rule on the form
Code:
  *[target]:after {content: "[" attr(target) "]";}
in my user stylesheet to warn me about target attributes

/RS.
Ronin SpoilSpot is offline   Reply With Quote
Old Jun 27, 2003, 18:30   #20
hurricane.uk
SitePoint Addict
 
hurricane.uk's Avatar
 
Join Date: May 2003
Location: Liverpool
Posts: 361
Quote:
Originally Posted by terts
We have been using this code for some time now on our site. Problem is we call the script using the onClick attribute, which does not validate in XML transitional 1.0.
Try making it all lower case, so onclick
hurricane.uk is offline   Reply With Quote
Old Jun 28, 2003, 04:37   #21
billiousness
SitePoint Wizard
 
Join Date: Apr 2002
Location: Brisbane QLD Australia
Posts: 1,690
Quote:
Originally Posted by Optimum
Keep in mind popups are great to use AT TIMES but more and more people are purchasing or downloading for free, popup blocker software. Eg.

"EarthLink rolled out Pop-Up Blocker in August. EarthLink provided Pop-Up Blocker for free download to its 4.7 million members. The company does not release the number of users who have downloaded the software, estimating only that it is "well into the six figures." "

I think anyway you get it done is fine, its just how much people will be blocking this window that should be a major concern.

People frown on anything they get their minds on. Microwaves were frowned upon once too. Can't make everyone happy.
this is a little of topic but I always thought(without researching or doing any correctly by just making an assumption) that pop up blocking software only blocked automatic pop ups. I asssumed new window pop-ups that were initiated by links were classed as like "friendly pop ups".

please tell me their friendly and that the blocking software don't block them too...
billiousness is offline   Reply With Quote
Old Jun 28, 2003, 04:53   #22
hurricane.uk
SitePoint Addict
 
hurricane.uk's Avatar
 
Join Date: May 2003
Location: Liverpool
Posts: 361
Quote:
Originally Posted by billiousness
please tell me their friendly and that the blocking software don't block them too...
My browser won't block user propagated windows, but my firewall will block some (and seemingly at random, I have that switched off anyway) - so I would say that some popup blockers would/may/can block the friendly kind.
hurricane.uk is offline   Reply With Quote
Old Jul 1, 2003, 13:43   #23
Bill Posters
SitePoint Wizard
 
Bill Posters's Avatar
 
Join Date: Dec 2001
Location: UK
Posts: 1,524
I'm looking for a way to specify that all links present inside an element with a certain id should open in _blank, while the rest of the links on that page open in _self* as per usual.

I don't have access to the <a> tags themselves, but I do have access to the surrounding tag element (in this case a <td>).
I can set an id for the <table>, <tr> or <td> (or can create and id another container such as a <span> or <div> if it somehow makes things easier).

Code:
...

<a href="1.html">1</a>
<a href="2.html">2</a>
<a href="3.html">3</a>

<table id="theseLinks">
  <tr>
    <td> <!-- everything within this cell is included from a 3rd party source -->
      <a href="4.html">4</a>
      <a href="5.html">5</a>
      <a href="6.html">6</a>
    </td>
  </tr>
</table>

<a href="7.html">7</a>
<a href="8.html">8</a>
<a href="9.html">9</a>

...
Basically, links 1-3 and 7-9 should open _self as normal.
Links 4-6 should open open in _blank.

I'm thinking that there may be some way to adapt Yank's method that will allow me to do this.

Anyone able to tell me how?


Big TIA
Bill Posters is offline   Reply With Quote
Old Jul 1, 2003, 14:20   #24
jofa
Sultan of Ping
 
jofa's Avatar
 
Join Date: Mar 2002
Location: Svíþjóð
Posts: 4,101
Do an "Inverse Yank": Give your links the attribute rel="internal", and change the script to
Code:
...
if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") != "internal")
     anchor.target = "_blank"; 
...
jofa is offline   Reply With Quote
Old Jul 1, 2003, 14:22   #25
Bill Posters
SitePoint Wizard
 
Bill Posters's Avatar
 
Join Date: Dec 2001
Location: UK
Posts: 1,524
I'd considered that, but it would mean giving every other link on the page a rel="internal" and thats hardly an efficient way of doing things.

but thx for trying though.


The search continues...
Bill Posters is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 07:30.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved