Results 1 to 5 of 5

Thread: the presence of objects

  1. #1

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    the presence of objects

    i currently do this in one of my pages:

    parent.document.getElementById('UseageBar').innerHTML = "bla";

    but the UseageBar (or the parent too on occasions) will not always exist - how can i detect their presence first, so that i do not get an error when displaying my page?

    thanks
    Kris

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    Code:
    if (parent) 
    {
      if (parent.document.getElementById('UseageBar'))
      {
           ...
           ..
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    is the first if (parent) necessary?
    The 2nd if will still see if the thing exists, if it doesn't it wont access it. I don't think the 1st if is necessary
    Have I helped you? Please Rate my posts.

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    Probably not - but I garuntee it will work
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    If you don't check for the existence of parent and then try to access it as in the second if you'll get a JavaScript error. Most people won't even notice, but it can cause unexpected effects.

    For example
    Code:
    if(parent.document.getElementById('some')) {
      // This is executed if both parent and some exist.
    } else {
      // This is executed if parent exists but some doesn't.
    }
    // Neither  part, nor anything here, is executed if parent doesn't exists.
    // A JS error cancels script execution.
    You could use try...catch to find out if parent doesn't exist.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width