Get img from cell in Firefox

Discussion in 'ASP .Net' started by Joe, Apr 2, 2008.

  1. Joe

    Joe Guest

    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
     
    Joe, Apr 2, 2008
    #1
    1. Advertising

  2. Joe

    Joe Guest

    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
    >
     
    Joe, Apr 2, 2008
    #2
    1. Advertising

  3. Joe

    Joe Guest

    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
    >
     
    Joe, Apr 2, 2008
    #3
  4. 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.src);
    imgs.alt = imgs.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/subscriptions/managednewsgroups/default.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/subscriptions/support/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
    >>

    >
    >
    >
     
    Steven Cheng [MSFT], Apr 3, 2008
    #4
  5. Joe

    marss Guest

    On 2 Кві, 23:30, "Joe" <> 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
     
    marss, Apr 3, 2008
    #5
  6. Joe

    Joe Guest

    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.src);
    > imgs.alt = imgs.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/subscriptions/managednewsgroups/default.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/subscriptions/support/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
    >>>

    >>
    >>
    >>

    >
     
    Joe, Apr 3, 2008
    #6
  7. 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.src);
    >> imgs.alt = imgs.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/subscriptions/managednewsgroups/default.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/subscriptions/support/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
    >>>>
    >>>
    >>>
    >>>

    >>

    >
    >
    >
     
    Steven Cheng [MSFT], Apr 4, 2008
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. news.austin.rr.com

    how to download img from html img tag

    news.austin.rr.com, Apr 27, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    539
    Steve C. Orr [MVP, MCSD]
    Apr 27, 2005
  2. Philipp Lenssen

    Problem: <img></img>

    Philipp Lenssen, Jun 27, 2005, in forum: XML
    Replies:
    15
    Views:
    805
    David Håsäther
    Jul 3, 2005
  3. Jopek
    Replies:
    7
    Views:
    428
    dorayme
    Apr 26, 2009
  4. Replies:
    7
    Views:
    206
    Tad McClellan
    Jun 22, 2006
  5. Replies:
    2
    Views:
    265
    Thomas 'PointedEars' Lahn
    Aug 5, 2008
Loading...

Share This Page