|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Base Target using Javascript
Hi,
Is there a way to have all offsite links open in a new window? Links not at http://www.forum_domainname.com will have target="_blank" applied. The pages are on a Remotely Hosted Forum. All URL's are absolute. All I can do is add Javascript to the Header or Footer. Cheers, Degs Last edited by degsy : September 22nd, 2002 at 04:22 PM. |
|
#2
|
|||
|
|||
|
degsy...
In <head>er: <script type="text/javascript" language="javascript"> function setTargets() { var link, l = 0; while (link = document.links[l++]) { if (link.href.indexOf('http://www.forum_domainname.com') == -1) link.target = '_blank'; } } </script> Stick this at the bottom of the file, after all link HTML: <script type="text/javascript" language="javascript"> setTargets(); </script> You can also run it onload, if preferable. |
|
#3
|
|||
|
|||
|
I've ran into a problem.
I've just realised that the forum URL's are in the form of http://forumdomain.com/forumname e.g. http://forumdomain.com/forumname1 http://forumdomain.com/forumname2 http://forumdomain.com/forumname3 and the posts are http://forumdomain.com/forumname.post1 http://forumdomain.com/forumname.post2 http://forumdomain.com/forumname.post3 Can I change the URL in the script so that it works with this format. Possibly using the .length method? |
|
#4
|
|||
|
|||
|
degsy...ya lost me...what posts?
OK; assuming the 'posts' are the 'offsite' links... if (link.href.indexOf('.post') != -1) Something like that. Some real sample urls would help (if those aren't). |
|
#5
|
|||
|
|||
|
Ok,
The board is at http://pub53.ezboard.com/buhelpcanhelpforum The forum URL's then differ slightly. e.g. The Notices and Announcement forum URL is http://pub53.ezboard.com/fuhelpcanhelpforumfrm23 Then a Topic is http://pub53.ezboard.com/fuhelpcanhelpforumfrm23.showMessage?topicID=41.topic What I would like is that all URL's that are not part of those 3 formats to open in a New Window. So a link posted to http://www.google.com would open a new window. This is default for several messageboard programs, but not for ezboard ![]() |
|
#6
|
|||
|
|||
|
Maybe I'm misunderstanding...can't be this simple:
<html> <head> <script type="text/javascript" language="javascript"> function setTargets() { var link, l = 0; while (link = document.links[l++]) { if (link.href.indexOf('uhelpcanhelpforum') == -1) link.target = '_blank'; } } onload = setTargets; </script> </head> <body> <a href="http://pub53.ezboard.com/buhelpcanhelpforum">board</a><br> <a href="http://pub53.ezboard.com/fuhelpcanhelpforumfrm23">n & a</a><br> <a href="http://pub53.ezboard.com/fuhelpcanhelpforumfrm23.showMessage?topicID=41.topic">topic</a><br> <a href="http://www.google.com">google</a> </body> </html> Last edited by adios : September 23rd, 2002 at 01:08 PM. |
|
#7
|
|||
|
|||
|
Yes, but alot of other forums are hosted on ezboard.
I would also class them as "offsite" links. So i would like the script for anything with uhelpcanhelpforum (buhelpcanhelpforum or fuhelpcanhelpforum) Thanks for persisting with this ![]() |
|
#8
|
|||
|
|||
|
You're a nice chap, no problem. Edited the above, tell me if I'm close...
rob |
|
#9
|
|||
|
|||
|
Works perfectly.
Although I have found some other problems implementing it, but I'll have a play around with it. For 2 URL's I could use this? <script type="text/javascript" language="javascript"> function setTargets() { var url1 = 'uhelpcanhelpforum' var url2 = 'another_url' var link, l = 0; while (link = document.links[l++]) { if (link.href.indexOf(url1) == -1 || link.href.indexOf(url2) == -1) link.target = '_blank'; } } onload = setTargets; </script> Thanks for your time. ![]() |
|
#10
|
|||
|
|||
|
My final offer
:<html> <head> <script type="text/javascript" language="javascript"> var checkURLs = new Array( 'uhelpcanhelpforum' , 'another_url' , 'yet_another_url' ); function setTargets() { var link, checkit, i, l = 0; while (link = document.links[l++]) { i = 0; while (checkit = checkURLs[i++]) if (link.href.indexOf(checkit) != -1) break; if (i > checkURLs.length) link.target = '_blank'; } } onload = setTargets; </script> </head> <body> <a href="http://pub53.ezboard.com/buhelpcanhelpforum">-1-</a><br> <a href="http://www.google.com/another_url">-2-</a><br> <a href="http://www.google.com/yet_another_url">-3-</a><br> <a href="http://www.google.com">google</a> </body> </html> |
|
#11
|
|||
|
|||
|
Cool
![]() That'll do nicely ![]() Cheers, Degs |
![]() |
| Viewing: Dev Shed Forums > Web Design > JavaScript Development > Base Target using Javascript |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|