Revisions
- October 18, 2012 @ 05:44:10 [Current Revision] by PeterLugg
- October 18, 2012 @ 05:42:28 by PeterLugg
Revision Differences
October 18, 2012 @ 05:42:28 | Current Revision | ||
---|---|---|---|
Content | |||
Added: Taken from here: <a href="http:// techstudio.co/web-design/ the-best-way- to-make-links- open-in-a-new-window" target="_blank" >http://techstudio.co/web- design/the-best- way-to-make- links-open-in- a-new-window</a> | |||
Added: The old method for setting links up to open in a new window causes validation errors in xHTML. | |||
Added: [html]<code><a href=</code> <code>"#" </code> <code>target= </code> <code> "_blank" </code> <code>>link</ a></code>[/html] | |||
Added: The right way is to use the following markup. | |||
Added: [html]<code><a href=</code> <code>"#" </code> <code>rel= </code> <code> "external"</ code><code> >link< /a></code>[/html] | |||
Added: But for that markup to work the following Javascript must be included in your document. | |||
Added: [js]<code> function</code> <code>externalLinks() {</code> | |||
Added: <div>< code> </code> <code>if</code> <code>( !document.getElementsByTagName) </code> <code>return</code> <code>; </code> </div> | |||
Added: <div>< code> </code> <code>var</code> <code>anchors = document.getElementsByTagName( </code> <code> "a" </code> <code>) ;</code> </div> | |||
Added: <div>< code> </code> <code>for</code> <code>( </code> <code> var</code> <code>i=0; i<anchors.length; i++) {</code> </div> | |||
Added: <div>< code> < /code>< code>var</code> <code>anchor = anchors[i];< /code></div> | |||
Added: <div>< code> < /code>< code>if</code> <code>( anchor.getAttribute(</ code><code>" href"< /code><code>) && anchor.getAttribute( </code> <code> "rel" </code> <code>) == </code> <code>" external" </code> <code>) anchor.target = </code> <code>" _blank" </code> <code> ;</code> </div> | |||
Added: <div>< code> </code> <code>}</code> </div> | |||
Added: <div>< code>}< /code></div> | |||
Deleted: | Added: [/js] |
Note: Spaces may be added to comparison text to allow better line wrapping.
No comments yet.