|
|||||||
New to SitePoint Forums? Register here for free!
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
SitePoint Co-Founder
![]() 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." |
|
|
|
|
|
#2 |
|
SitePoint Enthusiast
![]() 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? |
|
|
|
|
|
#3 |
|
SitePoint Wizard
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Dec 2001
Location: UK
Posts: 1,524
|
|
|
|
|
|
|
#4 |
|
SitePoint Addict
![]() ![]() ![]() Join Date: Apr 2002
Location: Tucson, AZ
Posts: 224
|
But what about people who disable javascript?
|
|
|
|
|
|
#5 | ||
|
SitePoint Wizard
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Dec 2001
Location: UK
Posts: 1,524
|
Quote:
Quote:
|
||
|
|
|
|
|
#6 |
|
SitePoint Addict
![]() ![]() ![]() Join Date: Apr 2002
Location: Tucson, AZ
Posts: 224
|
well that answers it...thanks billl
|
|
|
|
|
|
#7 |
|
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?
|
|
|
|
|
|
#8 | |
|
☆★☆★
![]() Join Date: Jan 2002
Location: in transition
Posts: 21,481
|
Quote:
Code:
<a href="mypage.html" onclick="window.open(this.href, 'newWin', 'width=300, height=450');">My Link</a> |
|
|
|
|
|
|
#9 | |
|
gingham dress, army boots...
![]() Join Date: Apr 2002
Location: Salford / Manchester / UK
Posts: 4,856
|
Quote:
Code:
<a href="mypage.html" onclick="window.open(this.href, 'newWin', 'width=300, height=450'); return false;">My Link</a> |
|
|
|
|
|
|
#10 | |
|
☆★☆★
![]() Join Date: Jan 2002
Location: in transition
Posts: 21,481
|
Quote:
|
|
|
|
|
|
|
#11 |
|
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 |
|
|
|
|
|
#12 |
|
SitePoint Zealot
![]() ![]() 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. |
|
|
|
|
|
#13 |
|
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.
|
|
|
|
|
|
#14 | |
|
Wanna-be Apple nut
![]() Join Date: Sep 2000
Location: Halmstad, Sweden
Posts: 7,614
|
Quote:
|
|
|
|
|
|
|
#15 |
|
SitePoint Member
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. |
|
|
|
|
|
#16 | |
|
☆★☆★
![]() Join Date: Jan 2002
Location: in transition
Posts: 21,481
|
Quote:
. |
|
|
|
|
|
|
#17 | |
|
Sultan of Ping
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Mar 2002
Location: Svíþjóð
Posts: 4,101
|
Quote:
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";
}
}
|
|
|
|
|
|
|
#18 |
|
SitePoint Member
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 ![]() |
|
|
|
|
|
#19 |
|
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";
}
}
}
}
Code:
*[ref="external"]:after {content:url(external.png);}
Code:
*[target]:after {content: "[" attr(target) "]";}
/RS. |
|
|
|
|
|
#20 | |
|
SitePoint Addict
![]() ![]() ![]() Join Date: May 2003
Location: Liverpool
Posts: 361
|
Quote:
![]() |
|
|
|
|
|
|
#21 | |
|
SitePoint Wizard
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Apr 2002
Location: Brisbane QLD Australia
Posts: 1,690
|
Quote:
please tell me their friendly and that the blocking software don't block them too... |
|
|
|
|
|
|
#22 | |
|
SitePoint Addict
![]() ![]() ![]() Join Date: May 2003
Location: Liverpool
Posts: 361
|
Quote:
|
|
|
|
|
|
|
#23 |
|
SitePoint Wizard
![]() ![]() ![]() ![]() ![]() ![]() 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>
...
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 |
|
|
|
|
|
#24 |
|
Sultan of Ping
![]() ![]() ![]() ![]() ![]() ![]() 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";
...
|
|
|
|
|
|
#25 |
|
SitePoint Wizard
![]() ![]() ![]() ![]() ![]() ![]() 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... |
|
|
|
![]() |
| Bookmarks |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
|
All times are GMT -7. The time now is 07:30.








.



Linear Mode
