By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,574 Members | 1,459 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,574 IT Pros & Developers. It's quick & easy.

getElementsByTagName, outerHTML, innerHTML in mozilla...

P: n/a
Pai
Hello there,

I have the following peice of javascript which works with IE but would
not work with mozilla.

In IE the first for loop is entered but in mozilla i would not enter
the for loop any tips / ideas?
var tblObj=document.body.getElementsByTagName("TD")

for(var iTblObjLoop=0;iTblObjLoop<tblObj.length;iTblObjLoo p++)
{
var sTempStr=new String(tblObj[iTblObjLoop].outerHTML)
alert(sTempStr);
//ms-banner contains the Portal Links
if(sTempStr.indexOf("ms-banner",1)>0)
{
var aDivs = tblObj[iTblObjLoop].getElementsByTagName("A");
for(var i=0;i<aDivs.length - 1;i++)
{
//If hlMySite Exists, change it to 'Admin' Link
if(aDivs[i].outerHTML.indexOf("hlMySite",1)>0)
{
hlMySite.outerHTML="<a target='_self' id='hlMySite'
href='default.aspx' title='Admin'>Admin</a><BR><BR>"
}
/*
If SettingsOrReturnURL Exists, Append "<BR><BR>" to the Link to
make the rest of the
links to come on the next line
*/
if(aDivs[i].outerHTML.indexOf("SettingsOrReturnURL",1)>0)
{
SettingsOrReturnURL.outerHTML=SettingsOrReturnURL. outerHTML +
"<BR><BR>"
}
}
break
}
}

Any help would be appreciated,

Thanks,
Srikanth Pai
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On 1 May 2004 10:47:44 -0700, Pai <sp**@immunetolerance.org> wrote:
I have the following peice of javascript which works with IE but would
not work with mozilla.
Please, don't use tabs when posting code. Replace them with 2 or 4 spaces.
In IE the first for loop is entered but in mozilla i would not enter
the for loop any tips / ideas?
I should think that it enters the first loop, but errors immediately with
the first statement of that loop - the outerHTML property.
var tblObj=document.body.getElementsByTagName("TD")

for(var iTblObjLoop=0;iTblObjLoop<tblObj.length;iTblObjLoo p++)
{
var sTempStr=new String(tblObj[iTblObjLoop].outerHTML)
The outerHTML property is always a string. Why are you creating a string
object?
alert(sTempStr);
//ms-banner contains the Portal Links
if(sTempStr.indexOf("ms-banner",1)>0)
Or more commonly:

if( -1 != sTempStr.indexOf( 'ms-banner' ))
{
var aDivs = tblObj[iTblObjLoop].getElementsByTagName("A");
for(var i=0;i<aDivs.length - 1;i++)
{
//If hlMySite Exists, change it to 'Admin' Link
if(aDivs[i].outerHTML.indexOf("hlMySite",1)>0)
if( -1 != aDivs[ i ].outerHTML.indexOf( 'hlMySite' ))
{
hlMySite.outerHTML="<a target='_self' id='hlMySite' " +
"href='default.aspx' title='Admin'>Admin</a><BR><BR>"
Is it really necessary to completely replace the link? Wouldn't it be
simpler to modify the appropriate attributes?
}
/*
If SettingsOrReturnURL Exists, Append "<BR><BR>" to the Link
to make the rest of the links to come on the next line
*/
if(aDivs[i].outerHTML.indexOf("SettingsOrReturnURL",1)>0)
{
SettingsOrReturnURL.outerHTML=SettingsOrReturnURL. outerHTML +
"<BR><BR>"
}
}
break
}
}


To make this appropriate for the Internet, it would require a lot of
changes. For a start, feature detection. However, it seems that this would
best be performed on a server, not a client.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #2

P: n/a

Hello Mike,

Thanks for your reply,

It does not enter the first loop it self I am positive, I put an alert
statement right after the for loop and i could not see the popup? any
other suggestions / ideas why it is not getting through?

var tblObj=document.body.getElementsByTagName("TD")
for(var itblobjloop=0;itblobjloop<tblobj.length;itblobjloo p++)
{
alert('hello');
var sTempStr=new String(tblObj[iTblObjLoop].outerHTML)

Thanks
Srikanth Pai
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #3

P: n/a
On 02 May 2004 11:56:55 GMT, Srikanth Pai <sp**@immunetolerance.org> wrote:
It does not enter the first loop it self I am positive, I put an alert
statement right after the for loop and i could not see the popup? any
other suggestions / ideas why it is not getting through?
It wouldn't matter anyway; Mozilla doesn't support the outerHTML property
(not many browsers do).

Have you checked the length of the collection held in tblObj to see if any
elements were found? Are you certain of correct capitalisation? The
snippet below doesn't have the same capitalisation as in your previous
post, and there are inconsistencies, too.

Seeing a test page is the only sure way to debug it.
var tblObj=document.body.getElementsByTagName("TD")
for(var itblobjloop=0;itblobjloop<tblobj.length;itblobjloo p++)
{
alert('hello');
var sTempStr=new String(tblObj[iTblObjLoop].outerHTML)


Once again, the outerHTML property returns a string in every browser that
supports it (most don't and will return undefined), so creating a string
object is a waste of browser resources.

I apologise for being blunt, but the script you presented should be
scrapped. It relies on proprietary, and DOM, features; none of which are
tested.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.