iEntry 10th Anniversary Forum Rules Search
WebProWorld
Register FAQ Calendar Mark Forums Read
Graphics & Design Discussion Forum Post your graphics design questions/comments/ideas in here. Ask questions, post tutorials, discuss trends and best practices. Sub-forum for website accessibility and usability.

Share Thread: & Tags

Share Thread:

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-29-2003, 06:23 PM
WebProWorld Veteran
 
Join Date: Jul 2003
Location: Bristol, UK
Posts: 521
carbonize RepRank 0
Default Using javascript instead of target="_blank"

How would I do a link that uses javascript to open a new window but at the same time degrades so that it's a normal link when they have javascript turned off?

Code:
blah
I know the window.open part is right but it's getting the current window not to change unless they have javascript turned off thats eluding me.
__________________
Carbonize
Reply With Quote
  #2 (permalink)  
Old 11-29-2003, 08:55 PM
Narasinha's Avatar
WebProWorld Pro
 
Join Date: Aug 2003
Location: Urbana, Illinois, US
Posts: 232
Narasinha RepRank 1
Default Re: Using javascript instead of target="_blank"

Quote:
Originally Posted by carbonize
How would I do a link that uses javascript to open a new window but at the same time degrades so that it's a normal link when they have javascript turned off?
I read a good article about how to do it. I put an example up at http://www.soltec.net/~dmg/external/index.html. The links on this page go to the same document, but one link is structured differently. The normal link is just a simple "href=", but the external has the attribute rel="external" added like this:
The "rel" attribute is intended to specify the relationship between the document that contains the link, and the target of the link. We all know the standard types of this for linking to style sheets, next, previous, etc., but the specs allow any custom value you want for site-specific purposes. This is just what is needed for compliant targeted windows.

In the head of the document, an external javascript is called. It's done this way because it is assumed you would want the external links function available from several pages. The head of the page has this call to the JavaScript file:
Code:
<script type="text/javascript" src="external.js">
</script>
The external.js script file has this content:
Code:
function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}
window.onload = externalLinks;
The 'externalLinks' function is called when the page loads. It then adds the target attribute, in a standards-compliant manner, to the links that have the 'rel="external"' attribute. It would seem that this is cheating, in a way, but since the target attribute is used only through the DOM in JavaScript, it is according to specs.

Try out the external link on the page with JavaScript turned off and turned on. It has the desired effect of a new window when on, and a normal link when off.
Reply With Quote
Reply

  WebProWorld > Site Design > Graphics & Design Discussion Forum

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
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 05:55 AM.



Search Engine Optimization by vBSEO 3.3.0