/    Sign up×
Community /Pin to ProfileBookmark

document.getElementsByTagName backdoor

Hey, what if a vistor to your website has an old browser that doesn’t have the function document.getElementsByTagName already defined?
I have already created a backdoor for the document.getElementById function,
see my sig.

This thread will be used to develop such a function at Mr. Anonymous ‘s request.

My current progress with the function requires the user’s browser to be either
FF or IE…I’m working on getting it to work with NS.
Also, do any early browsers support [color=royalblue]nodeName[/color] or [color=royalblue]outterHTML[/color] if they don’t already have nodeName defined?

Here’s my progress:
(I renamed the function to getElement[b]z[/b]ByTagName for testing purposes)

[code=html]
<SCRIPT LANGUAGE=”JavaScript” TYPE=”text/javascript”>
if(document.all)
document.getElementzByTagName=function(){
arguments[0]=arguments[0].toUpperCase()
var temp=[]
for(var i in document.all){
if(document.all[i].nodeName==arguments[0])
temp[temp.length]=document.all[i]
}
return temp
}

onload=function(){
var e=document.getElementzByTagName(“a”)
alert(e[0].ElementMessage+”n”+e[1].ElementMessage)
}
</SCRIPT>
<a ElementMessage=”first tag”>
<a ElementMessage=”second tag”>
[/code]

to post a comment
JavaScript

14 Comments(s)

Copy linkTweet thisAlerts:
@KorApr 14.2005 — If you are thinking on old browers which do not recognize DOM methods, maybe you should try to cross-browser for NS4 (document.layers) rather than for IE4 (document.all) as I don't think that anyone uses IE 4 anymore...
Copy linkTweet thisAlerts:
@David_HarrisonApr 14.2005 — Why not simply let older browsers try and fail to understand the JavaScript? Let them fall back on the no-JavaScript compatibilty that your pages of course have.
Copy linkTweet thisAlerts:
@UltimaterauthorApr 14.2005 — Kor,

yes, I am creating a backdoor for old browsers which do no recognize the DOM method.

I'm not trying to be picky about which old browsers deserve a backdoor.

Every old browser is my target that I can successfully define the function for.

If any browser doesn't recognize the built-in function, then my statement will actually define the function by creating the function if it doesn't already exist.

The easiest way to do so is:
[code=php]
if(!document.getElementsByTagName)
document.getElementsByTagName=function(){
//define function here
}
[/code]
Copy linkTweet thisAlerts:
@UltimaterauthorApr 14.2005 — Why not simply let older browsers try and fail to understand the JavaScript? Let them fall back on the no-JavaScript compatibilty that your pages of course have.[/QUOTE]
I don't want old browsers to be turned-down if there is a possible way to "serve" them.

My reasons for creating this function are the same for creating the function

document.getElementsById in the past.

Sure, the vast majority have up-to-date browsers, but what about the remaining people with old browsers?

I'm even part of this remainder, my notebook computer is 5-years old and still has IE 3.0 or 4.0 on it.

It is too slow to properly run any later versions...

Another reason why I didn't upgrade my laptop's browser is because it actually

severs useful when testing new scripts that I develop.
Copy linkTweet thisAlerts:
@UltimaterauthorApr 14.2005 — Hey, if any any knows where I can get my hand on a compatibility chart for [color=royalblue]nodeName[/color] or [color=royalblue]outterHTML[/color], please let me know. If you present me with a link, you'd have done half the work of creating this function for me.

*Goes to the drawing-board*
Copy linkTweet thisAlerts:
@UltimaterauthorApr 14.2005 — Hmm... I ran into some kind of chart but it doesn't tell me anything about old browsers...

[url=http://or.bolbusiness.it/resources/HTML/DOM/V5%20Briwser%20Compatibility%20Chart.html]W3C DOM Compatibility Table[/url]

I apologize on my mis-spelling of [color=royalblue]outerHTML[/color] before...
Copy linkTweet thisAlerts:
@UltimaterauthorApr 14.2005 — Hmm... I also noticed that I will need to make getElementsByTagName a prototype-function as well in-order to get the Tag of a Tag...
Copy linkTweet thisAlerts:
@UltimaterauthorApr 14.2005 — hmm... what's the differnece between [color=royalblue]tagName[/color] and [color=royalblue]nodeName[/color]?
Copy linkTweet thisAlerts:
@KorApr 15.2005 — hmm... what's the differnece between [color=royalblue]tagName[/color] and [color=royalblue]nodeName[/color]?[/QUOTE]

[b]nodeName[/b] is a complex attribute. It works in close relationship with [b]nodeType[/b]. According to the [b]nodeType[/b], [b]nodeName[/b] may return the tag's name, the tag's attribute, may select text nodes, and so on ond so forth.

Ex

obj = document.childNodes;

for(var i=0;i<obj.length;i++){

if(obj[i].nodeType==1){

if(obj[i].nodeName=='a'){// if the objects are a tags

...do smth

}

}

else if(obj[i].nodeType==2){

if(obj[i].nodeName=='href'){// if the objects have 'href' attributes

...do smth

}

}

else if(obj[i].nodeType==3){

if(obj[i].nodeName=='#text'){// if the objects are text nodes

...do smth

}

}

}





There are 12 [b]nodeType[/b], amongs which you may return comments, doctype... and so on... Google for complete refrence
Copy linkTweet thisAlerts:
@UltimaterauthorApr 20.2005 — Thanx, Kor! So in this case, document.getElementsByTagName, I should use [color=royalblue]tagName[/color].

Any idea if it's supported in IE3.0 ,IE4.0 or in early NS?
Copy linkTweet thisAlerts:
@David_HarrisonApr 20.2005 — No idea, why don't you [url=http://browsers.evolt.org/]have a look[/url] and tell us. ?
Copy linkTweet thisAlerts:
@UltimaterauthorApr 20.2005 — Hmm... I think I'll wait until I move back to my hometown and use my LabTop with IE4.0...

I'm not sure how I'm gonna do this...

It is gonna be very hard to add this function as a prototype to every element...

Is there like an Element.prototype property or something?

The function is supposed to be able to be called like:

document.getElementById("blah")[color=royalblue].getElementsByTagName("img")[/color]

Any ideas on how to add a prototype function to every existing element?
Copy linkTweet thisAlerts:
@David_HarrisonApr 20.2005 — All of those versions of IE are stand-alone versions. You just download, extract and run. No mess, no fuss.

You'd do this:Object.prototype.getElementsByTagName = function () {

// Your code here

}{

}
But it won't work in any version of IE because it sucks the veiny one.
Copy linkTweet thisAlerts:
@UltimaterauthorApr 21.2005 — [color=royalblue]Object[/color] works with prototype!? I didn't know that...

You say it works but not in IE.... hmm...

That would explain why it didn't work for me back-when.

Some time ago I tried using Object.prototype and it didn't work, I thought it was rather strange that Object didn't work with prototype if there are already Date, Image, Array, String, Number, Function...

This function is gonna be much harder to create than I thought....
×

Success!

Help @Ultimater spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...