473,320 Members | 1,953 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

how do I make this case-insensitive

Hi Folk

I have the following function:

function eli() {
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";
}
}
}

I run this function here : <body onload="eli();">. It adds the
target="_blank" attribute to all links that are written as follows:

<A HREF="http://www.somefruitcakesite.com" rel="external">my link</a>

How do I make it case insensitive. So that it also picks up:

<A href="http://www.somefruitcakesite.com" rel="EXTERNAL">my link</a>
<A href="http://www.somefruitcakesite.com" REL="external">my link</a>

etc...

Or is that too much work and should I adjust my html.

TIA
Nicolaas

Apr 23 '06 #1
4 2256
> How do I make it case insensitive?

Change
if (anchor.getAttribute("HREF") && anchor.getAttribute("rel") == "external") {
To
if (anchor.getAttribute("HREF") && ( anchor.getAttribute("rel").toLowerCase == "external" || anchor.getAttribute("REL").toLowerCase == "external" ) ) {


This should do the trick. You may want to put in the same || for your
HREF too, since if you are serving this page as xml+xhtml (or use a
XHTML DOCTYPE in some browsers) all attributes are case sensitive.

<opinion about="standards" intent="friendly advice">On the other hand,
while this will make your code work, in reality you should probabally
standardize on using all lowercase -- if you are using XHTML lowercase
is required and if not, when you wind up eventually upgrading you won't
have as much maintenance to do. HTML Tidy (http://tidy.sf.net) can
automate this for you on your attribute names, but the values would be
up to you.</opinion>

Apr 23 '06 #2
> "windandwaves" <wi*********@coldmail.com> wrote:
news:aL********************@news.xtra.co.nz....

Hi Folk

I have the following function:

function eli() {
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";
}
}
}

I run this function here : <body onload="eli();">. It adds the
target="_blank" attribute to all links that are written as follows:

<A HREF="http://www.somefruitcakesite.com" rel="external">my
link</a>

How do I make it case insensitive. So that it also picks up:

<A href="http://www.somefruitcakesite.com" rel="EXTERNAL">my
link</a> <A href="http://www.somefruitcakesite.com"
REL="external">my link</a>

etc...

Or is that too much work and should I adjust my html.

Adjustments would be a good ideal.

<script type="text/javascript">
function eli() {
var i,j,elix;
for (i=0, j=document.links.length; i<j; i++) {
elix=document.links[i];
if(elix.href && elix.rel.match(/external/i)){
elix.target="_blank";
}}}
</script>

--
BootNic Saturday, April 22, 2006 11:52 PM

"This is all very interesting, and I daresay you already see me
frothing at the mouth in a fit; but no, I am not; I am just winking
happy thoughts into a little tiddle cup."
*Nabokov, Lolita*

Apr 23 '06 #3
Joshie Surber wrote:
How do I make it case insensitive?
Change
if (anchor.getAttribute("HREF") && anchor.getAttribute("rel") == "external") {


To
if (...toLowerCase == "external" ...toLowerCase == "external" ...

----------------------^^ --------------------------^^

getLowerCase is a method, use:

if (...toLowerCase() == "external" ...toLowerCase()...


This should do the trick. You may want to put in the same || for your
HREF too, since if you are serving this page as xml+xhtml (or use a
XHTML DOCTYPE in some browsers) all attributes are case sensitive.

<opinion about="standards" intent="friendly advice">On the other hand,
while this will make your code work, in reality you should probabally
standardize on using all lowercase -- if you are using XHTML lowercase
is required and if not, when you wind up eventually upgrading you won't
have as much maintenance to do. HTML Tidy (http://tidy.sf.net) can
automate this for you on your attribute names, but the values would be
up to you.</opinion>

--
Rob
Apr 23 '06 #4
Joshie Surber wrote:
How do I make it case insensitive?


Change
if (anchor.getAttribute("HREF") && anchor.getAttribute("rel") ==
"external") {


To
if (anchor.getAttribute("HREF") && (
anchor.getAttribute("rel").toLowerCase == "external" ||
anchor.getAttribute("REL").toLowerCase == "external" ) ) {


This should do the trick. You may want to put in the same || for your
HREF too, since if you are serving this page as xml+xhtml (or use a
XHTML DOCTYPE in some browsers) all attributes are case sensitive.

<opinion about="standards" intent="friendly advice">On the other hand,
while this will make your code work, in reality you should probabally
standardize on using all lowercase -- if you are using XHTML lowercase
is required and if not, when you wind up eventually upgrading you
won't have as much maintenance to do. HTML Tidy (http://tidy.sf.net)
can automate this for you on your attribute names, but the values
would be up to you.</opinion>


Totally agree, I will actually do this, but it is a huge site:
www.friars.co.nz and it takes time to go through all the code (PHP) and
adjust (well, about four hours I estimate).

Thanks for the help.
Apr 23 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Newbie | last post by:
Dear friends, I am having a hard time understanding how to use a SELECT CASE in ASP. I have used it in VB but never in ASP scripting. Scenerio: I have 2 textboxes on a form that I have to...
9
by: Kevin | last post by:
Hi, I am getting a syntax error Microsoft VBScript compilation error '800a03ea' Syntax error On the code below. The error references the "End Select" line Can anyone help me with what I am...
5
by: Ryan | last post by:
I'm struggling with a Case statement. The problem I has is with doing >= I can use any value in there, but need to check if it's greater or equal to 1. I'm sure I'm missing something but can't...
2
by: cs168 | last post by:
Hi I am new in ASP programming so I do use the very basic and simple way to do all my stuff. Now I do really got stuck at how can I loop thru the calculation for all my selection.. My full code is as...
6
by: deanfamily11 | last post by:
I've set up a case statement to have my program determine where on the Cartesian plane a point the user enters is located. I keep getting the C2051 error when I compile. Any help? #include...
10
by: MLH | last post by:
Suppose the following... Dim A as Date A=#7/24/2005# I wish to compare value of A against 2 other values: 1) 8/1/2005 2) 9/1/2005 Which is better and why... First:
4
by: Samuels90 | last post by:
Hey everyone, My program is supposed to go to Column R Row 2. If Column M contain "01" it should run the "sum(if array" for that Case,(no pun intended), in Column R. Can someone tell me what is...
0
by: ANGanley | last post by:
Any ideas why i get an error in my script. set dateformat YMD set datefirst 7 CREATE TABLE #ChildSessions ( siteid integer null ,childid integer null ,sessionid integer null ,sun...
4
by: clairelee0322 | last post by:
My program has an error C2360: initialization of 'i' is skipped by 'case' label. I don't know why. Please help me out! thks!! the error occurs in Division case 3. //Claire's Calculator...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.