JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 22nd, 2002, 04:12 PM
degsy degsy is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2001
Posts: 1,882 degsy User rank is Sergeant (500 - 2000 Reputation Level)degsy User rank is Sergeant (500 - 2000 Reputation Level)degsy User rank is Sergeant (500 - 2000 Reputation Level)degsy User rank is Sergeant (500 - 2000 Reputation Level)degsy User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 Days 21 h 19 m 30 sec
Reputation Power: 14
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.

Reply With Quote
  #2  
Old September 22nd, 2002, 09:10 PM
adios adios is offline
Senior Citizen
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2001
Location: leftcoast
Posts: 2,019 adios User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 10
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.

Reply With Quote
  #3  
Old September 23rd, 2002, 12:02 PM
degsy degsy is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2001
Posts: 1,882 degsy User rank is Sergeant (500 - 2000 Reputation Level)degsy User rank is Sergeant (500 - 2000 Reputation Level)degsy User rank is Sergeant (500 - 2000 Reputation Level)degsy User rank is Sergeant (500 - 2000 Reputation Level)degsy User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 Days 21 h 19 m 30 sec
Reputation Power: 14
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?

Reply With Quote
  #4  
Old September 23rd, 2002, 12:25 PM
adios adios is offline
Senior Citizen
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2001
Location: leftcoast
Posts: 2,019 adios User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 10
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).

Reply With Quote
  #5  
Old September 23rd, 2002, 12:32 PM
degsy degsy is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2001
Posts: 1,882 degsy User rank is Sergeant (500 - 2000 Reputation Level)degsy User rank is Sergeant (500 - 2000 Reputation Level)degsy User rank is Sergeant (500 - 2000 Reputation Level)degsy User rank is Sergeant (500 - 2000 Reputation Level)degsy User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 Days 21 h 19 m 30 sec
Reputation Power: 14
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

Reply With Quote
  #6  
Old September 23rd, 2002, 12:47 PM
adios adios is offline
Senior Citizen
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2001
Location: leftcoast
Posts: 2,019 adios User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 10
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.

Reply With Quote
  #7  
Old September 23rd, 2002, 01:04 PM
degsy degsy is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2001
Posts: 1,882 degsy User rank is Sergeant (500 - 2000 Reputation Level)degsy User rank is Sergeant (500 - 2000 Reputation Level)degsy User rank is Sergeant (500 - 2000 Reputation Level)degsy User rank is Sergeant (500 - 2000 Reputation Level)degsy User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 Days 21 h 19 m 30 sec
Reputation Power: 14
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

Reply With Quote
  #8  
Old September 23rd, 2002, 01:13 PM
adios adios is offline
Senior Citizen
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2001
Location: leftcoast
Posts: 2,019 adios User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 10
You're a nice chap, no problem. Edited the above, tell me if I'm close...

rob

Reply With Quote
  #9  
Old September 23rd, 2002, 01:33 PM
degsy degsy is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2001
Posts: 1,882 degsy User rank is Sergeant (500 - 2000 Reputation Level)degsy User rank is Sergeant (500 - 2000 Reputation Level)degsy User rank is Sergeant (500 - 2000 Reputation Level)degsy User rank is Sergeant (500 - 2000 Reputation Level)degsy User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 Days 21 h 19 m 30 sec
Reputation Power: 14
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.

Reply With Quote
  #10  
Old September 23rd, 2002, 02:12 PM
adios adios is offline
Senior Citizen
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2001
Location: leftcoast
Posts: 2,019 adios User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 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>

Reply With Quote
  #11  
Old September 23rd, 2002, 02:16 PM
degsy degsy is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2001
Posts: 1,882 degsy User rank is Sergeant (500 - 2000 Reputation Level)degsy User rank is Sergeant (500 - 2000 Reputation Level)degsy User rank is Sergeant (500 - 2000 Reputation Level)degsy User rank is Sergeant (500 - 2000 Reputation Level)degsy User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 Days 21 h 19 m 30 sec
Reputation Power: 14
Cool
That'll do nicely

Cheers,
Degs

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Base Target using Javascript


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT