473,804 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how do I make this case-insensitive

Hi Folk

I have the following function:

function eli() {
if (!document.getE lementsByTagNam e) return;
var anchors = document.getEle mentsByTagName( "A");
for (var i=0; i<anchors.lengt h; i++) {
var anchor = anchors[i];
if (anchor.getAttr ibute("HREF") && anchor.getAttri bute("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.somefruitca kesite.com" rel="external"> my link</a>

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

<A href="http://www.somefruitca kesite.com" rel="EXTERNAL"> my link</a>
<A href="http://www.somefruitca kesite.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 2278
> How do I make it case insensitive?

Change
if (anchor.getAttr ibute("HREF") && anchor.getAttri bute("rel") == "external") {
To
if (anchor.getAttr ibute("HREF") && ( anchor.getAttri bute("rel").toL owerCase == "external" || anchor.getAttri bute("REL").toL owerCase == "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="standard s" intent="friendl y 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
> "windandwav es" <wi*********@co ldmail.com> wrote:
news:aL******** ************@ne ws.xtra.co.nz.. ..

Hi Folk

I have the following function:

function eli() {
if (!document.getE lementsByTagNam e) return;
var anchors = document.getEle mentsByTagName( "A");
for (var i=0; i<anchors.lengt h; i++) {
var anchor = anchors[i];
if (anchor.getAttr ibute("HREF") && anchor.getAttri bute("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.somefruitca kesite.com" rel="external"> my
link</a>

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

<A href="http://www.somefruitca kesite.com" rel="EXTERNAL"> my
link</a> <A href="http://www.somefruitca kesite.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.link s.length; i<j; i++) {
elix=document.l inks[i];
if(elix.href && elix.rel.match(/external/i)){
elix.target="_b lank";
}}}
</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.getAttr ibute("HREF") && anchor.getAttri bute("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="standard s" intent="friendl y 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.getAttr ibute("HREF") && anchor.getAttri bute("rel") ==
"external") {


To
if (anchor.getAttr ibute("HREF") && (
anchor.getAttri bute("rel").toL owerCase == "external" ||
anchor.getAttri bute("REL").toL owerCase == "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="standard s" intent="friendl y 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
14651
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 allow entry to one or the other or Both at the same time. Now I tried to use an If ElseIf but it got too hard to track, so now I am using a SELECT CASE Statement.
9
3635
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 doing wrong? Thanks
5
3044
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 figure out what. I've put the line below in case anyone has any suggestions. I've limited it to the offending line, but can add more if needed. This version works ------------------ CASE m.Splinter_Status WHEN 'SUR' THEN 0 ELSE CASE m.Sacrifice...
2
3211
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 below:- <% tBegin = request("beginww") tEnd = request("endww") tYear = request("wwyear") %> <body>
6
4704
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 <iomanip> #include <iostream> using namespace std;
10
2173
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
1522
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 wrong with my code? Cheers! Sub GLAmount()
0
1313
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 integer default 0
4
24990
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 #include <iostream.h> #include <math.h>
0
9714
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9594
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10346
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10347
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9173
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7635
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4308
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.