473,833 Members | 2,116 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getElementsByTa gName, outerHTML, innerHTML in mozilla...

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.getElemen tsByTagName("TD ")

for(var iTblObjLoop=0;i TblObjLoop<tblO bj.length;iTblO bjLoop++)
{
var sTempStr=new String(tblObj[iTblObjLoop].outerHTML)
alert(sTempStr) ;
//ms-banner contains the Portal Links
if(sTempStr.ind exOf("ms-banner",1)>0)
{
var aDivs = tblObj[iTblObjLoop].getElementsByT agName("A");
for(var i=0;i<aDivs.len gth - 1;i++)
{
//If hlMySite Exists, change it to 'Admin' Link
if(aDivs[i].outerHTML.inde xOf("hlMySite", 1)>0)
{
hlMySite.outerH TML="<a target='_self' id='hlMySite'
href='default.a spx' title='Admin'>A dmin</a><BR><BR>"
}
/*
If SettingsOrRetur nURL Exists, Append "<BR><BR>" to the Link to
make the rest of the
links to come on the next line
*/
if(aDivs[i].outerHTML.inde xOf("SettingsOr ReturnURL",1)>0 )
{
SettingsOrRetur nURL.outerHTML= SettingsOrRetur nURL.outerHTML +
"<BR><BR>"
}
}
break
}
}

Any help would be appreciated,

Thanks,
Srikanth Pai
Jul 23 '05 #1
3 11277
On 1 May 2004 10:47:44 -0700, Pai <sp**@immunetol erance.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.getElemen tsByTagName("TD ")

for(var iTblObjLoop=0;i TblObjLoop<tblO bj.length;iTblO bjLoop++)
{
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.ind exOf("ms-banner",1)>0)
Or more commonly:

if( -1 != sTempStr.indexO f( 'ms-banner' ))
{
var aDivs = tblObj[iTblObjLoop].getElementsByT agName("A");
for(var i=0;i<aDivs.len gth - 1;i++)
{
//If hlMySite Exists, change it to 'Admin' Link
if(aDivs[i].outerHTML.inde xOf("hlMySite", 1)>0)
if( -1 != aDivs[ i ].outerHTML.inde xOf( 'hlMySite' ))
{
hlMySite.outerH TML="<a target='_self' id='hlMySite' " +
"href='default. aspx' title='Admin'>A dmin</a><BR><BR>"
Is it really necessary to completely replace the link? Wouldn't it be
simpler to modify the appropriate attributes?
}
/*
If SettingsOrRetur nURL Exists, Append "<BR><BR>" to the Link
to make the rest of the links to come on the next line
*/
if(aDivs[i].outerHTML.inde xOf("SettingsOr ReturnURL",1)>0 )
{
SettingsOrRetur nURL.outerHTML= SettingsOrRetur nURL.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.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #2

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.getElemen tsByTagName("TD ")
for(var itblobjloop=0;i tblobjloop<tblo bj.length;itblo bjloop++)
{
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
On 02 May 2004 11:56:55 GMT, Srikanth Pai <sp**@immunetol erance.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.getElemen tsByTagName("TD ")
for(var itblobjloop=0;i tblobjloop<tblo bj.length;itblo bjloop++)
{
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.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #4

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

Similar topics

1
9119
by: Ted Weatherly | last post by:
Hello, I want to dynamically create a table cell with a textfield in it. The value for the textfield can have quotes. e.g. I have this snippet of javascript code: var td = document.createElement('td'); var cellMarkup = '<input value="&quot;test&quot;">'; td.innerHTML = cellMarkup;
1
2792
by: Nicolas Van Lancker | last post by:
Hi folks; I have this webpage, allowing users to insert multiple records in one post into the database. Because I don't know the exact number of records they want to add, I created a little javascript that adds a new line with HTML inputboxes and lists to the form if they press a button.
4
1993
by: norfleet | last post by:
hi folks, OK, so let's say, for example, I have a bit of HTML that looks like this: <td class="regular1b" valign="top"> <a href="notfound.html"><span class="list5"><b>Lecture V</b></span></a> </td>
4
17234
by: harry | last post by:
Using IE 5.5 (sp2) - no other I have a table that need's to be sorted by single column using javascript. I have the code to do this but because of the attributes associated with the <tr> element, when the sorted values are copied back in to the table I want to replace the entire row not just the inner values! Any ideas why this doesn't work?
8
7778
by: Clément | last post by:
Hi! I am currently developping a user interface with Ajax/C#/.net. And I am facing a problem with Mozilla, and Firefox. I use the function innerHTML to load a Web UserControl into a div, this way the main page never gets refreshed. It works perfectly under IE, but with Mozilla and Firefox I got a problem : there is a space before the thing I want to display everytime I use ".innerHTML".
3
2312
by: David Virgil Hobbs | last post by:
I discovered how to write out the inner HTML of the contents of an Iframe; I want to know how to write out the outerHTML of the contents of an Iframe. frames.document.body.innerHTML allows me to read the inner HTML of the contents of an iframe and also allows me to write out the inner HTML of the contents of an iframe. However using frames.document.body.innerHTML I am only able to change, in the contents of the iframe, the code in...
1
2605
by: rishabhshrivastava | last post by:
Hey All, I want to get the OuterHtml in a TextBox and I am using following code but I am getting value as "undefined" Please let me know if I am doing anything wrong.. function GetValue() { document.getElementById("txtBox").value = parent.main.document.documentElement.outerhtml ; return document.getElementById("txtBox").value;
5
5332
by: eBob.com | last post by:
I am so frustrated. I've been working all weekend on what I thought would be a simple script. I never find it easy to look at someone else's code, but if someone can help with this I would be very grateful. The script is .... <script type="text/javascript"> var parentwin = external.menuArguments; var doc = parentwin.document; var x = doc.getElementsByTagName("table") alert(x.length + " table things")
0
9642
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
10500
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
10543
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
10213
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7753
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
5789
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4422
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
2
3972
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3078
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.