Web Analytics Made Easy -
StatCounter Can somebody explain this ? - CodingForum

Announcement

Collapse
No announcement yet.

Can somebody explain this ?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can somebody explain this ?

    Hi

    I have the following code, if you just run it on a browser (IE6 to be precise) it is self explicative of the problem:

    //---------------------------

    var out=new Array(0)
    var count=0;
    for(var i in window){
    ++count;
    out[++out.length-1]=window[i]
    if(!confirm("property " + count + " value (out of 37 properties) is = " + window[i] + "\n\nIf you press cancel, last alert would yield all these values in a string, if you let the loop go to the end pressing only OK and NEVER cancel, the last alert shows... nothing!!\n\nIf you replace windows[i] in the codes just with I, the last alert shows the summary.")){break}
    }
    alert("summary of values should be = "+out)

    //---------------------------


    Any idea why it happens? I'm fighting with browser object properties. They even have alias: have you ever tried this:

    alert(top.top.top.top.top.top.top.self.self.self.top.self.window.top.self.frames.frames.frames.locat ion)

    well, it gives the location of the document: it means that top carries as a property of its own a property whose name is top: in this way instead of generating the error, produces a result: the dire consequence is that you cannot safely make a recursive function on browser properties! Also, some properties have aliases: somebody thoguht it was a cool idea to arrange browsers properties this way uh!

    :-(

    Anyway, if you've ideas on the code above...
    Alberto http://www.unitedscripters.com/

  • #2
    What I'm finding after an input by John who was attempting to loop object properties is really unexpected.
    For it really seems that one thing is looping "objects", a completely different one is... looping a BROWSER's objects!

    The following code can be tested on IE5++
    It produces a confirm box with the name of the currently scanned object. As soon as the object becomes "plugins" it stops with an error. "plugins" is a property object of the document object.
    The only part of the script you may be interested in is after the comment: //run:

    ---------


    function extractProperties(object, radix, output){
    if(!output){
    //object preferably passed as string name of the object
    /*The idea is to put all objects in one NUMERICALLY indexed array named output, then loop it at a second moment and populate it with the properties*/
    //initialize:
    output=new Array(0);
    var firstObjName=(object && typeof(object)=="string")?object:
    (object && typeof(object)!="string")?"":"window";
    object=(object && typeof(object)=="string")?eval(object):
    (object && typeof(object)!="string")?object:window;
    UNPREObject=function(obj, objName){
    this.obj=obj;
    this.objName=(objName)?objName:"";
    this.typeis=typeof(this.obj);
    this.objects=new Array();
    this.methods=new Array();
    this.properties=new Array();
    this.objectPath=new Array(0);//stores names
    }
    radix=object;//attempting to bypass aliases!
    //run:
    }
    for(var s in object){
    var typ=typeof(object[s]);
    if((radix!=object[s]) && (typ=="object" || typ=="function")){
    if(!confirm(s)){return false}
    output[++output.length-1]=new UNPREObject(object, s);
    extractProperties(object[s], radix, output)
    };
    }
    return output}

    extractProperties("window");


    ---------

    Such function can unfold nested objects like the following snippet:

    ----

    var foo=new Object()
    foo.prop1=1
    foo.prop2=2
    foo.obj1=new Object()
    foo.obj1.propr1="obj1.propr1"
    foo.obj1.obj1b=new Object()
    foo.obj1.obj1b.obj1b2=new Object()
    foo.obj2=new Object()
    foo.prop3=3
    foo.obj3=new Array()
    foo.obj3.obj4=foo;/*radix to prove it can bypass these tricks*/
    foo.obj3["fooooo"]=new Array(8,9)

    ----

    In fact by calling:

    alert(extractProperties("foo"));

    produces a sensible output.

    If you use it with "windows" as object argument, it stops as soon as it meets "plugins".


    Also, see this:

    alert(window["clientInformation"])

    it produces: [object Navigator]

    uh, seems that Navigator is indeed a class. Therefore try:

    alert(window["clientInformation"].appVersion)

    oh yes, it gives the application version info. Only problem, what is the meaning of a property "clientInformation" on IE5++ which is basically nothing else than a Navigator object emulation??

    This "clientInformation" Navigator like Object properties are:

    appCodeName
    appName
    appMinorVersion
    cpuClass
    platform
    plugins
    opsProfile
    userProfile
    systemLanguage
    userLanguage
    appVersion
    userAgent
    onLine
    cookieEnabled

    let's see if it is an extended class of Navigator: Navigator properties are:

    appCodeName
    appName
    appMinorVersion
    cpuClass
    platform
    plugins
    opsProfile
    userProfile
    systemLanguage
    userLanguage
    appVersion
    userAgent
    onLine
    cookieEnabled

    No,. it is NOT: it is identical, extends nothing.

    What is this stuff then? What is it for?
    No wonder john coudln't loop these ... "objects"!!
    original post:


    ciao........
    Last edited by TrueLies; Jun 25, 2002, 12:23 AM.
    Alberto http://www.unitedscripters.com/

    Comment

    Working...
    X