|
-
Apr 21st, 2004, 04:13 PM
#1
the presence of objects
i currently do this in one of my pages:
parent.document.getElementById('UseageBar').innerHTML = "bla";
but the UseageBar (or the parent too on occasions) will not always exist - how can i detect their presence first, so that i do not get an error when displaying my page?
thanks
Kris
-
Apr 21st, 2004, 04:18 PM
#2
Code:
if (parent)
{
if (parent.document.getElementById('UseageBar'))
{
...
..
-
Apr 21st, 2004, 04:24 PM
#3
Frenzied Member
is the first if (parent) necessary?
The 2nd if will still see if the thing exists, if it doesn't it wont access it. I don't think the 1st if is necessary
Have I helped you? Please Rate my posts. 
-
Apr 21st, 2004, 04:32 PM
#4
Probably not - but I garuntee it will work
-
Apr 22nd, 2004, 03:20 AM
#5
If you don't check for the existence of parent and then try to access it as in the second if you'll get a JavaScript error. Most people won't even notice, but it can cause unexpected effects.
For example
Code:
if(parent.document.getElementById('some')) {
// This is executed if both parent and some exist.
} else {
// This is executed if parent exists but some doesn't.
}
// Neither part, nor anything here, is executed if parent doesn't exists.
// A JS error cancels script execution.
You could use try...catch to find out if parent doesn't exist.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|