Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Get img from cell in Firefox

Reply
Thread Tools

Get img from cell in Firefox

 
 
Joe
Guest
Posts: n/a
 
      04-02-2008
Hello all!

I'm trying to change the src of imgs in 5 different cells so I iterate
through the cells in the table and do this:
var img = table.rows[0].cells[n].firstChild;
img.src = some url

This works fine in IE but not in any other browser. What's the trick here?

Thanks,
Joe


 
Reply With Quote
 
 
 
 
Joe
Guest
Posts: n/a
 
      04-02-2008
Actually I guess it's rendered as an input. I'm using ImageButtons that I'm
trying to change.

"Joe" <> wrote in message
news:...
> Hello all!
>
> I'm trying to change the src of imgs in 5 different cells so I iterate
> through the cells in the table and do this:
> var img = table.rows[0].cells[n].firstChild;
> img.src = some url
>
> This works fine in IE but not in any other browser. What's the trick here?
>
> Thanks,
> Joe
>



 
Reply With Quote
 
 
 
 
Joe
Guest
Posts: n/a
 
      04-02-2008
Now it looks like my problem is I cannot get/set the title.

"Joe" <> wrote in message
news:...
> Hello all!
>
> I'm trying to change the src of imgs in 5 different cells so I iterate
> through the cells in the table and do this:
> var img = table.rows[0].cells[n].firstChild;
> img.src = some url
>
> This works fine in IE but not in any other browser. What's the trick here?
>
> Thanks,
> Joe
>



 
Reply With Quote
 
Steven Cheng [MSFT]
Guest
Posts: n/a
 
      04-03-2008
Hi Joe,

As for loop through all the image(or other html elements in a html table),
I would suggeest you use the "document.getElementByTagName" function as
it's the standard DOM interface which works on both IE and firebox. The "
table.rows[0].cells[n].firstChild;" syntax is somewhat coupled with IE
browser. Here is a simple test page demonstrate this:

===========================================
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function get_img_in_table(tbid)
{
var tb = document.getElementById(tbid);

var imgs = document.getElementsByTagName("IMG");

var i =0;

for(i=0;i<imgs.length;++i)
{
alert(imgs[i].src);
imgs[i].alt = imgs[i].src;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table id="tbImages" >
<tr>
<td>image:</td>
<td><img
src="http://www.asp.net/App_Themes/Standard/i/logo.png" /></td>
</tr>

<tr>
<td>image:</td>
<td><img
src="http://static.asp.net/asp.net/images/books/book13.gif" /></td>
</tr>

<tr>
<td>image:</td>
<td><img src="http://ads.asp.net/ads/200_50_aspnet_gr.gif"
/></td>
</tr>
</table>

<br />
<input type="button" value="get image in table"
onclick="get_img_in_table('tbImages');" />
</div>
</form>
</body>
==============================================

BTW, for your new question about setting the "title", would you tell me
what' the title you mentioned? is it the page title or title of some other
html element on page?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>From: "Joe" <>
>References: <>
>Subject: Re: Get img from cell in Firefox
>Date: Wed, 2 Apr 2008 17:30:30 -0400
>
>Now it looks like my problem is I cannot get/set the title.
>
>"Joe" <> wrote in message
>news:...
>> Hello all!
>>
>> I'm trying to change the src of imgs in 5 different cells so I iterate
>> through the cells in the table and do this:
>> var img = table.rows[0].cells[n].firstChild;
>> img.src = some url
>>
>> This works fine in IE but not in any other browser. What's the trick

here?
>>
>> Thanks,
>> Joe
>>

>
>
>


 
Reply With Quote
 
marss
Guest
Posts: n/a
 
      04-03-2008
On 2 Кві, 23:30, "Joe" <jbassk...@noemail.noemail> wrote:
> Hello all!
>
> I'm trying to change the src of imgs in 5 different cells so I iterate
> through the cells in the table and do this:
> var img = table.rows[0].cells[n].firstChild;
> img.src = some url
>
> This works fine in IE but not in any other browser. What's the trick here?
>
> Thanks,
> Joe


Hi Joe,

Little addition to the Steven's post.
document.getElementsByTagName("IMG") returns all images on a page.
table, tr, td elements also have getElementsByTagName method and you
can reduce result images set if you use it.

Regarding of firstChild.
In Firefox it depends on HTML structure, if there is a gap between td
and img tags then the first child is a text node.
1. <td><img ... - firstChild is image
2. <td> <img ... - firstChild is text node

Regards,
Mykola
http://marss.co.ua


 
Reply With Quote
 
Joe
Guest
Posts: n/a
 
      04-03-2008
The getElemenetByTagName worked to fix my issue. Thanks.

"Steven Cheng [MSFT]" <> wrote in message
news:...
> Hi Joe,
>
> As for loop through all the image(or other html elements in a html table),
> I would suggeest you use the "document.getElementByTagName" function as
> it's the standard DOM interface which works on both IE and firebox. The "
> table.rows[0].cells[n].firstChild;" syntax is somewhat coupled with IE
> browser. Here is a simple test page demonstrate this:
>
> ===========================================
> <head runat="server">
> <title>Untitled Page</title>
> <script type="text/javascript">
> function get_img_in_table(tbid)
> {
> var tb = document.getElementById(tbid);
>
> var imgs = document.getElementsByTagName("IMG");
>
> var i =0;
>
> for(i=0;i<imgs.length;++i)
> {
> alert(imgs[i].src);
> imgs[i].alt = imgs[i].src;
> }
> }
> </script>
> </head>
> <body>
> <form id="form1" runat="server">
> <div>
> <table id="tbImages" >
> <tr>
> <td>image:</td>
> <td><img
> src="http://www.asp.net/App_Themes/Standard/i/logo.png" /></td>
> </tr>
>
> <tr>
> <td>image:</td>
> <td><img
> src="http://static.asp.net/asp.net/images/books/book13.gif" /></td>
> </tr>
>
> <tr>
> <td>image:</td>
> <td><img src="http://ads.asp.net/ads/200_50_aspnet_gr.gif"
> /></td>
> </tr>
> </table>
>
> <br />
> <input type="button" value="get image in table"
> onclick="get_img_in_table('tbImages');" />
> </div>
> </form>
> </body>
> ==============================================
>
> BTW, for your new question about setting the "title", would you tell me
> what' the title you mentioned? is it the page title or title of some other
> html element on page?
>
> Sincerely,
>
> Steven Cheng
>
> Microsoft MSDN Online Support Lead
>
>
> Delighting our customers is our #1 priority. We welcome your comments and
> suggestions about how we can improve the support we provide to you. Please
> feel free to let my manager know what you think of the level of service
> provided. You can send feedback directly to my manager at:
> .
>
> ==================================================
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/subscripti...ult.aspx#notif
> ications.
>
> Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the community or a Microsoft Support
> Engineer within 1 business day is acceptable. Please note that each follow
> up response may take approximately 2 business days as the support
> professional working with you may need further investigation to reach the
> most efficient resolution. The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions or complex
> project analysis and dump analysis issues. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by contacting
> Microsoft Customer Support Services (CSS) at
> http://msdn.microsoft.com/subscripti...t/default.aspx.
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
> --------------------
>>From: "Joe" <>
>>References: <>
>>Subject: Re: Get img from cell in Firefox
>>Date: Wed, 2 Apr 2008 17:30:30 -0400
>>
>>Now it looks like my problem is I cannot get/set the title.
>>
>>"Joe" <> wrote in message
>>news:...
>>> Hello all!
>>>
>>> I'm trying to change the src of imgs in 5 different cells so I iterate
>>> through the cells in the table and do this:
>>> var img = table.rows[0].cells[n].firstChild;
>>> img.src = some url
>>>
>>> This works fine in IE but not in any other browser. What's the trick

> here?
>>>
>>> Thanks,
>>> Joe
>>>

>>
>>
>>

>



 
Reply With Quote
 
Steven Cheng [MSFT]
Guest
Posts: n/a
 
      04-04-2008
Thanks for your reply Joe,

I'm glad that it helps you.

Have a nice day!

Sincerely,

Steven Cheng
Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
.
========================================
>From: "Joe" <>
>References: <>

<>
<>
>Subject: Re: Get img from cell in Firefox
>Date: Thu, 3 Apr 2008 12:06:39 -0400


>
>The getElemenetByTagName worked to fix my issue. Thanks.
>
>"Steven Cheng [MSFT]" <> wrote in message
>news:...
>> Hi Joe,
>>
>> As for loop through all the image(or other html elements in a html

table),
>> I would suggeest you use the "document.getElementByTagName" function as
>> it's the standard DOM interface which works on both IE and firebox. The "
>> table.rows[0].cells[n].firstChild;" syntax is somewhat coupled with IE
>> browser. Here is a simple test page demonstrate this:
>>
>> ===========================================
>> <head runat="server">
>> <title>Untitled Page</title>
>> <script type="text/javascript">
>> function get_img_in_table(tbid)
>> {
>> var tb = document.getElementById(tbid);
>>
>> var imgs = document.getElementsByTagName("IMG");
>>
>> var i =0;
>>
>> for(i=0;i<imgs.length;++i)
>> {
>> alert(imgs[i].src);
>> imgs[i].alt = imgs[i].src;
>> }
>> }
>> </script>
>> </head>
>> <body>
>> <form id="form1" runat="server">
>> <div>
>> <table id="tbImages" >
>> <tr>
>> <td>image:</td>
>> <td><img
>> src="http://www.asp.net/App_Themes/Standard/i/logo.png" /></td>
>> </tr>
>>
>> <tr>
>> <td>image:</td>
>> <td><img
>> src="http://static.asp.net/asp.net/images/books/book13.gif" /></td>
>> </tr>
>>
>> <tr>
>> <td>image:</td>
>> <td><img src="http://ads.asp.net/ads/200_50_aspnet_gr.gif"
>> /></td>
>> </tr>
>> </table>
>>
>> <br />
>> <input type="button" value="get image in table"
>> onclick="get_img_in_table('tbImages');" />
>> </div>
>> </form>
>> </body>
>> ==============================================
>>
>> BTW, for your new question about setting the "title", would you tell me
>> what' the title you mentioned? is it the page title or title of some

other
>> html element on page?
>>
>> Sincerely,
>>
>> Steven Cheng
>>
>> Microsoft MSDN Online Support Lead
>>
>>
>> Delighting our customers is our #1 priority. We welcome your comments and
>> suggestions about how we can improve the support we provide to you.

Please
>> feel free to let my manager know what you think of the level of service
>> provided. You can send feedback directly to my manager at:
>> .
>>
>> ==================================================
>> Get notification to my posts through email? Please refer to
>>

http://msdn.microsoft.com/subscripti...ult.aspx#notif
>> ications.
>>
>> Note: The MSDN Managed Newsgroup support offering is for non-urgent

issues
>> where an initial response from the community or a Microsoft Support
>> Engineer within 1 business day is acceptable. Please note that each

follow
>> up response may take approximately 2 business days as the support
>> professional working with you may need further investigation to reach the
>> most efficient resolution. The offering is not appropriate for situations
>> that require urgent, real-time or phone-based interactions or complex
>> project analysis and dump analysis issues. Issues of this nature are best
>> handled working with a dedicated Microsoft Support Engineer by contacting
>> Microsoft Customer Support Services (CSS) at
>> http://msdn.microsoft.com/subscripti...t/default.aspx.
>> ==================================================
>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
>> --------------------
>>>From: "Joe" <>
>>>References: <>
>>>Subject: Re: Get img from cell in Firefox
>>>Date: Wed, 2 Apr 2008 17:30:30 -0400
>>>
>>>Now it looks like my problem is I cannot get/set the title.
>>>
>>>"Joe" <> wrote in message
>>>news:...
>>>> Hello all!
>>>>
>>>> I'm trying to change the src of imgs in 5 different cells so I iterate
>>>> through the cells in the table and do this:
>>>> var img = table.rows[0].cells[n].firstChild;
>>>> img.src = some url
>>>>
>>>> This works fine in IE but not in any other browser. What's the trick

>> here?
>>>>
>>>> Thanks,
>>>> Joe
>>>>
>>>
>>>
>>>

>>

>
>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
putting img above/bellow img ? Jopek HTML 7 04-26-2009 10:26 PM
cell's offsetHeight not equal to cell's height?? firefox & IE laszlokenez@gmail.com Javascript 2 08-05-2008 10:44 PM
how to replace this like <img width=100 ...> with <img width="100" ...> zhanye815@gmail.com Perl Misc 7 06-21-2006 11:16 PM
Problem: <img></img> Philipp Lenssen XML 15 07-03-2005 09:23 AM
how to download img from html img tag news.austin.rr.com ASP .Net 2 04-27-2005 06:25 PM



Advertisments