www.webdeveloper.com
Results 1 to 5 of 5

Thread: Object detection

  1. #1
    Join Date
    Sep 2003
    Location
    Utah
    Posts
    396

    Object detection

    I have the following assignment:

    var o = (opener.opener) ? opener.opener.document.f1 : (opener) ? opener.document.f1 : "x";

    When I browse directly to the page with the above I get the following:

    'opener.opener' is null or not an object

    I know it isn't an object. I thought I was testing for that with the above code. I thought the above would first look of opener.opener. If that existed, then the value of o would be opener.opener.document.f1, if not, then the code would check for the existence of opener. If found, then o would be assigned opener.document.f1. Finally, if neither opener.opener or opener exist, then o would equal "x".

    What am I missing?

  2. #2
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,226
    Dunno, <SCRIPT> tags maybe or have you just copied and pasted a single line from your code?
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  3. #3
    Join Date
    Feb 2006
    Posts
    2,927
    if opener is null it is an error to test opener.opener.

    test o=(opener && opener.opener)? first, it will stop at the first opener if it is null.

  4. #4
    Join Date
    Feb 2003
    Location
    Michigan, USA
    Posts
    5,773
    Code:
    var o = null;
    
    if (!!opener) {
      if (!!opener.opener) {
        o = opener.opener.document.f1;
      } else {
        o = opener.document.f1;
      }
    }
    
    if (!!o) {
      // o is a valid reference to a FORM tag, continue
    } else {
      // o is not a valid reference
    }
    Using the double "!!" is like using a double negative in English. It means "if not-not opener.opener." If that statement is true, then opener.opener is an object.

  5. #5
    Join Date
    Sep 2003
    Location
    Utah
    Posts
    396
    Thanks. I didn't know that. So I essentially reversed the order of the assignment to do as you suggest, test for opener first.

    var o = (opener) ? (opener.opener) ? opener.opener.document.f1 : opener.document.f1 : "x";


    Seems to work.

    Thanks again.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles