Use javascript to check objects properties.

I wish to look at all the properties of certain objects on my web page.


How can I do this in javascript??
Wanting2LearnManAsked:
Who is Participating?
 
hieloCommented:
var str="";
for( var property in obj)
{
  str += "\n"=property +"="+obj[property];
}

document.writeln( str );
0
 
ludofulopCommented:
function dump_props(obj, objName) {  
var result = "" ;  
for (var i in obj) {      
result += objName + "." + i + " = " + obj[i] + "<BR>"  
}  
result += "<HR>"  
return result
}

then use :

alert(dump_props(document.getElementById('someelement'), 'somelementname'));
0
 
BadotzCommented:
If you want to make sure you only get properties for your object (and not from things up the prototype chain), try this:

var ra = [];
for (var x in obj) {
    if (obj.hasOwnProperty(x)) {
        ra.push(x + '=' + obj[x]);
    }
}
alert(ra.join('\n'));
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Wanting2LearnManAuthor Commented:
Thanks guys for the replies, I used the following:
var str="";
for( var property in obj)
{
   if( obj[property] !== null && obj[property] !== "" )
   {
         str += "\n"=property +"="+obj[property];
   }
}

document.writeln( str );



The output I got was as follows from the QuickTime plugin: (Excuse the formatting)

childNodes=[object NodeList] canHaveHTML=false nodeName=OBJECT currentStyle=[object CSSCurrentStyleDeclaration] scrollLeft=0 hideFocus=false clientHeight=240 style=[object CSSStyleDeclaration] nodeType=1 id=movie1 aria-level=0 scopeName=HTML scrollTop=0 offsetWidth=320 filters=[object] isContentEditable=false scrollHeight=240 lastChild=[object HTMLParamElement] canHaveChildren=false isMultiLine=true offsetTop=1 parentNode=[object HTMLTableCellElement] tagName=OBJECT behaviorUrns=[object BehaviorUrnsCollection] disabled=false parentTextEdit=[object HTMLBodyElement] ownerDocument=[object HTMLDocument] offsetParent=[object HTMLTableCellElement] aria-posinset=0 tabIndex=0 parentElement=[object HTMLTableCellElement] children=[object HTMLCollection] readyState=4 contentEditable=inherit document=[object HTMLDocument] firstChild=[object HTMLParamElement] sourceIndex=23 isTextEdit=false isDisabled=false runtimeStyle=[object CSSStyleDeclaration] scrollWidth=320 attributes=[object NamedNodeMap] offsetHeight=240 clientTop=0 aria-setsize=0 clientWidth=320 outerHTML= No support for Embed??? clientLeft=0 all=[object HTMLCollection] innerHTML= offsetLeft=1 declare=false codeBase=http://www.apple.com/qtactivex/qtplugin.cab BaseHref=http://localhost:1539/WebSite3/test1.htm hspace=0 contentDocument=undefined vspace=0 altHtml= width=320 height=240


The problem is that the QuickTime plugin exposes other functions such as GetTime(), GetStatus() etc.

I need to get all these as well, how can I do this in javascript??


Many thank for your help so far.
0
 
HonorGodSoftware EngineerCommented:
What, exactly, are you looking for with respect to these function properties?

I use the following file (objDisplay.js) to display information about object/DOM element properties.

The code below, displays only the function properties of the specified object (in this case the button used to call the function).
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Dump function properties</title>
<script type='text/javascript' src='objDisplay.js'></script>
<script type='text/javascript'>
  function field( id ) {
    var ele = document.getElementById( id );
    if ( !ele ) {
      alert( 'Specified element not found. id="' + id + '"' );
    }
    return ele;
  }
  
  function dump( obj ) {
    var debug = field( 'debug' );
    if ( debug ) {
      debug.innerHTML += objDisplay( 'dump()', obj, 8 ) + '<br><br>';
    }
  }
</script>
</head>
<body>
<input type='button' value='dump' onclick='dump(this)'/>
<div id='debug'></div>
</body>
</html>

Open in new window

objDisplay.js.txt
0
 
BadotzCommented:
If you change

str += "\n"=property +"="+obj[property];

to

str += "<br />"=property +"="+obj[property];

you will get line breaks, and we will not get such a headache from your work.
0
 
Wanting2LearnManAuthor Commented:
Ok thanks guys.
Ok my proplem is this:
I have a QuickTIme player embedded on my web page.  It is viewing video from a server via rtsp.  The rtsp server can stream MJPEG and MP4.  If just MJPEG or MP4 is streamed then all is ok BUT if the video stream starts off MJPEG then changes to MP4 then Quicktime stops displaying the video at the point of changeover and I don't know why.

I thought an error event would be fired off which I could catch and then request a new stream but nothing is fired off.  Also if I call the GetTIme() function of the QuickTime plug-in I see that the time is still incrementing but the video is not being updated.

So far I have found no way to detect that QuickTIme has stopped playing the video.

I was hoping to check ALL the properties of the QuickTIme object and see if anything at all changes when this happens.

What do you guys think?  Do you have any ideas on how to solve this problem?

Thanks again.
0
 
Wanting2LearnManAuthor Commented:
Well any ideas anyone???
0
 
BadotzCommented:
Anything abour trappable events in the documentation?

Is there a QT forum where you can ask this question?
0
 
Wanting2LearnManAuthor Commented:
Yes I have asked it in the Apple QT forum and no replies :(

I will google trappable events and see what I can unearth

Thanks
0
 
BadotzCommented:
Perhaps ask in the QT forum here, too?
0
 
HonorGodSoftware EngineerCommented:
Thanks for the assist and the points.

Good luck & have a great day.
0
 
BadotzCommented:
No worries - glad to help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.