Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Use javascript to check objects properties.

Posted on 2010-01-08
13
Medium Priority
?
588 Views
Last Modified: 2012-05-08
I wish to look at all the properties of certain objects on my web page.


How can I do this in javascript??
0
Comment
Question by:Wanting2LearnMan
  • 5
  • 4
  • 2
  • +2
13 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 288 total points
ID: 26210217
var str="";
for( var property in obj)
{
  str += "\n"=property +"="+obj[property];
}

document.writeln( str );
0
 
LVL 15

Assisted Solution

by:ludofulop
ludofulop earned 288 total points
ID: 26210221
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
 
LVL 29

Assisted Solution

by:Badotz
Badotz earned 1140 total points
ID: 26210349
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:Wanting2LearnMan
ID: 26212237
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
 
LVL 41

Assisted Solution

by:HonorGod
HonorGod earned 284 total points
ID: 26213271
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
 
LVL 29

Assisted Solution

by:Badotz
Badotz earned 1140 total points
ID: 26213390
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
 

Author Comment

by:Wanting2LearnMan
ID: 26272515
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
 

Author Comment

by:Wanting2LearnMan
ID: 26281969
Well any ideas anyone???
0
 
LVL 29

Assisted Solution

by:Badotz
Badotz earned 1140 total points
ID: 26283119
Anything abour trappable events in the documentation?

Is there a QT forum where you can ask this question?
0
 

Author Comment

by:Wanting2LearnMan
ID: 26283241
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
 
LVL 29

Assisted Solution

by:Badotz
Badotz earned 1140 total points
ID: 26283270
Perhaps ask in the QT forum here, too?
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 26363250
Thanks for the assist and the points.

Good luck & have a great day.
0
 
LVL 29

Expert Comment

by:Badotz
ID: 26363282
No worries - glad to help.
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Is your phone running out of space to hold pictures?  This article will show you quick tips on how to solve this problem.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question