A question please

P

Peter

I'm new at this stuff -- so this is probably an incredibly dopey, newby
question. Please bear with me. I don't know if it's a HTML or javascript
question. (Or, if a different area altogether, please steer me to the right
group.)

I can view the members of the "window" object with the following javascript.
It returns all the methods, properties, events, etc.

<script type="text/javascript">
for(i in window)
{
window.document.write(i + "<br />");
}
</script>


I can do the same thing for the "document" object by changing the expression
to read...

<script type="text/javascript">
for(i in window.document)
{
window.document.write(i + "<br />");
}
</script>


And then I can check out an individual property, (example "protocol"), with
the following. It returns "HyperText Transfer Protocol".

<script type="text/javascript">
window.document.write(window.document.protocol);
</script>


So far, so good....

But -- I can't find a way to address the "html" or the "head" objects. I
know they're HTML elements, (<html>, <head>), but they also exist as objects
because I see on reference sites that they have methods, properties, events,
etc. So they've got to be child objects of some other object higher in the
hierarchy. Right? And there has to be some way to address them. Right?

For instance -- on the MSDN site, the docs say that the "innerText" property
of the "html" object, "Sets or retrieves the text between the start and end
tags of the object." OK -- using javascript, how do I "set" or "retrieve"
that property?

"window.html.innerText" doesn't work. Neither does
"window.document.hml.innerText". Is there an object higher than the window
object that "html" object is a child of?

Any help greatly appreciated. I've been staring at this *^#(%^ monitor for
about 8 hours now and my eyeballs are aching.
 
P

Peter Michaux

Peter said:
But -- I can't find a way to address the "html" or the "head" objects. I
know they're HTML elements, (<html>, <head>), but they also exist as objects
because I see on reference sites that they have methods, properties, events,
etc. So they've got to be child objects of some other object higher in the
hierarchy. Right? And there has to be some way to address them. Right?


This works for me in Opera 9

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>untitled</title>
</head>
<body>
<script type="text/javascript">
var html = document.getElementsByTagName('html')[0];
for (var p in html) {
document.write(p+'<br>');
}
</script>
</body>
</html>


For instance -- on the MSDN site, the docs say that the "innerText" property
of the "html" object, "Sets or retrieves the text between the start and end
tags of the object." OK -- using javascript, how do I "set" or "retrieve"
that property?

This works for me in Opera 9 to see the innerHTML. I don't know when
setting the innerHTML of the html element would be a good idea.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>untitled</title>
<script type="text/javascript">
window.onload=function() {
alert(document.getElementsByTagName('html')[0].innerHTML);
};
</script>
</head>
<body>
</body>
</html>


- Peter
 
J

Jonathan N. Little

Peter said:
I'm new at this stuff -- so this is probably an incredibly dopey, newby
question. Please bear with me. I don't know if it's a HTML or javascript
question. (Or, if a different area altogether, please steer me to the right
group.)

I can view the members of the "window" object with the following javascript.
It returns all the methods, properties, events, etc.

<script type="text/javascript">
for(i in window)
{
window.document.write(i + "<br />");
}
</script>


I can do the same thing for the "document" object by changing the expression
to read...

<script type="text/javascript">
for(i in window.document)
{
window.document.write(i + "<br />");
}
</script>


And then I can check out an individual property, (example "protocol"), with
the following. It returns "HyperText Transfer Protocol".

<script type="text/javascript">
window.document.write(window.document.protocol);
</script>


So far, so good....

But -- I can't find a way to address the "html" or the "head" objects. I
know they're HTML elements, (<html>, <head>), but they also exist as objects
because I see on reference sites that they have methods, properties, events,
etc. So they've got to be child objects of some other object higher in the
hierarchy. Right? And there has to be some way to address them. Right?

For instance -- on the MSDN site, the docs say that the "innerText" property
of the "html" object, "Sets or retrieves the text between the start and end
tags of the object." OK -- using javascript, how do I "set" or "retrieve"
that property?

"window.html.innerText" doesn't work. Neither does
"window.document.hml.innerText". Is there an object higher than the window
object that "html" object is a child of?

Any help greatly appreciated. I've been staring at this *^#(%^ monitor for
about 8 hours now and my eyeballs are aching.
1 Download a copy of Firefox.

2 Install with the "Custom Install" option to mark sure DOM Inspector is
checked

3 Or better yet, install the Web Developers Bar extension
https://addons.mozilla.org/firefox/60/

4 Open a web page and use the DOM Inspector to traverse the document
tree and view all the attributes.

An indispensable "learning|debugging" tool
 
P

Peter

Peter Michaux said:
Peter said:
But -- I can't find a way to address the "html" or the "head" objects. I
know they're HTML elements, (<html>, <head>), but they also exist as
objects
because I see on reference sites that they have methods, properties,
events,
etc. So they've got to be child objects of some other object higher in
the
hierarchy. Right? And there has to be some way to address them. Right?


This works for me in Opera 9

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>untitled</title>
</head>
<body>
<script type="text/javascript">
var html = document.getElementsByTagName('html')[0];
for (var p in html) {
document.write(p+'<br>');
}
</script>
</body>
</html>


For instance -- on the MSDN site, the docs say that the "innerText"
property
of the "html" object, "Sets or retrieves the text between the start and
end
tags of the object." OK -- using javascript, how do I "set" or "retrieve"
that property?

This works for me in Opera 9 to see the innerHTML. I don't know when
setting the innerHTML of the html element would be a good idea.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>untitled</title>
<script type="text/javascript">
window.onload=function() {
alert(document.getElementsByTagName('html')[0].innerHTML);
};
</script>
</head>
<body>
</body>
</html>


- Peter


Thanks. That works. Now I can get in and look around.

LOL. I guess I picked an extreme example. You're right -- I doubt I'd ever
have a reason to change that specific property.
 
P

Peter

Jonathan N. Little said:
1 Download a copy of Firefox.

2 Install with the "Custom Install" option to mark sure DOM Inspector is
checked

3 Or better yet, install the Web Developers Bar extension
https://addons.mozilla.org/firefox/60/

4 Open a web page and use the DOM Inspector to traverse the document tree
and view all the attributes.

An indispensable "learning|debugging" tool


Great tip. Thank you. When I got thrown into web development about a month
ago, I installed IE, Firefox, Opera and Netscape to do cross-browser
debugging. After checking out the Firefox DOM Inspector, I find that the
other three also have DOM inspectors. I haven't had a chance to look at them
all yet. This will keep me busy for weeks. :)
 
P

Peter Michaux

Jonathan said:
Hmmm, looks interesting. Ain't innovation great! Support "Open Source".

Firebug saves me a lot of time and I sent some money. I hope others do
to and keep it alive for a long time.

Peter
 
P

Peter Michaux

Peter said:
Great tip. Thank you. When I got thrown into web development about a month
ago, I installed IE, Firefox, Opera and Netscape to do cross-browser
debugging.

This is multi-browser debugging which is the practical approach but I
think your list needs Safari as it is distributed as the default
browser on all Macs. Safari has it's own set of oddities.

Peter
 
P

Peter

Peter Michaux said:
This is multi-browser debugging which is the practical approach but I
think your list needs Safari as it is distributed as the default
browser on all Macs. Safari has it's own set of oddities.

Peter

Is Safari available in a Windows version? I don't have a Mac available. I
checked the downloads at apple.com but didn't find anything.
 
P

Peter Michaux

Peter said:
Is Safari available in a Windows version? I don't have a Mac available. I
checked the downloads at apple.com but didn't find anything.

Unfortunately no and decent versions of IE aren't available for Mac. So
to develop for the mainstream part of the web you need OS X and
Windows. An Intel-based Mac with Parallels Desktop can do both but it
is a little bit of a pain still. At least you can tell your boss you
_need_ a fancy new MacBook Pro or the website might not work for many
people.

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top