Debugging IE

M

marksmith5555

I am writing a few scripts, primarily using firefox, with firebug
debugging is easy.

However when I try to run the script on IE7. I get the very unhelpful
error:

"Unknown runtime error": Line 38.

Line 38 doesn't even contain any javascript!!

After inserting lots of alert statements, I've tracked the error down
to this line of code:

cbs.innerHTML='<img src="../images/checkfalse.png"
onclick="checkBoxClick(this);" id="checkbox'+i+'" ><br>';

This works without problems on firefox and safari.

So actually I have 2 questions:

1) Can you suggest any way to modify the above line to work on IE7?
2) Are there any good debuggers for IE (that give better errors, and
allow you to set breakpoints etc)?

Thanks
 
M

marksmith5555


Thanks, unfortunatley the MS Script editor didn't shed much light on
the problem. It can see the object and innerHTML property just fine.
Yet it still throws an unknown error when I try to write to it.

Also, from the FAQ: "After enabling Script Debugging, a Script
Debugger option will appear in the View menu. "

I only have the option to open the debugger when an error gets thrown
as there is no view menu in IE7. Any idea where to find this option in
IE7?
 
R

rf

I am writing a few scripts, primarily using firefox, with firebug
debugging is easy.

However when I try to run the script on IE7. I get the very unhelpful
error:

"Unknown runtime error": Line 38.

IE always lies about the line number. It's probably the line number in the
HTML file that included the .js. And probably that plus one.
After inserting lots of alert statements, I've tracked the error down
to this line of code:

cbs.innerHTML='<img src="../images/checkfalse.png"
onclick="checkBoxClick(this);" id="checkbox'+i+'" ><br>';


What is in cbs? Have you alerted it? It just may be that whatever you
put there is not what you think it is (null for example) and you need to do
some feature detection.

If cbs is acually a DOM node then start with cbs.innerHTML = "" and
progress slowly from there.

Debugging 101.
 
M

marksmith5555

I am writing a few scripts, primarily using firefox, with firebug
debugging is easy.
However when I try to run the script on IE7. I get the very unhelpful
error:
"Unknown runtime error": Line 38.

IE always lies about the line number. It's probably the line number in the
HTML file that included the .js. And probably that plus one.
After inserting lots of alert statements, I've tracked the error down
to this line of code:
cbs.innerHTML='<img src="../images/checkfalse.png"
onclick="checkBoxClick(this);" id="checkbox'+i+'" ><br>';


What is in cbs? Have you alerted it?  It just may be that whatever you
put there is not what you think it is (null for example) and you need to do
some feature detection.

If cbs is acually a DOM node then start with cbs.innerHTML = "" and
progress slowly from there.

Debugging 101.


Yes, its definitely not null. I can read from it, and it all looks
fine in the debugger.

I've reproduced the problem on a stripped down html file:

<html>
<head>
<script language="javascript">
function test()
{
var tags=document.getElementsByTagName("test");
for(i=0;i<tags.length;i++)
tags.innerHTML='<p>Test';
}
</script>
</head>
<body onload="test();">
<test></test>
<test></test>
</body>
</html>
 
M

marksmith5555

Try playing around in the 'immediate' window to see if you can shed some
light on it. Can you assign anything simpler to innerHTML?





Press the Alt key: the menus are still there but only become visible when
you try to use them. There is also an option somewhere to make them always
visible but I can't remember where.

Excellent, thanks!
 
H

Henry

On Dec 15, 11:17 am, (e-mail address removed) wrote:
var tags=document.getElementsByTagName("test");
<body onload="test();">
<test></test>
<test></test>
</body>

HTML does not contain any elements with the tag name "test" so there
are no reasons for expecting any particular outcome here.
 
M

marksmith5555

On Dec 15, 11:17 am, (e-mail address removed) wrote:



HTML does not contain any elements with the tag name "test" so there
are no reasons for expecting any particular outcome here.

Not sure I follow. There are 2 <test> tags in that HTML document.

This works under Firefox and Safari.
 
E

Erwin Moller

(e-mail address removed) schreef:
Not sure I follow. There are 2 <test> tags in that HTML document.

This works under Firefox and Safari.

What works?
Do you see any difference between:

<test>I am in nonexistant tags named test</test>
and
I am in NOT nonexistant tags named test

Also try:
<hitherehowdoyoudo>Hi<hitherehowdoyoudo>

and

<DOYouLikeBananas>banana</DOYouLikeBananas>

Regards,
Erwin Moller

--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
 
G

Gregor Kofler

(e-mail address removed) meinte:
Not sure I follow. There are 2 <test> tags in that HTML document.

HTML doesn't know "test" tags. Period. Why do people always come up with
such, well, idiotic examples? Why no spans, divs, whatever?
This works under Firefox and Safari.

But not under IE apparently.

Gregor
 
M

marksmith5555

(e-mail address removed) schreef:








What works?
Do you see any difference between:

<test>I am in nonexistant tags named test</test>
and
I am in NOT nonexistant tags named test

Also try:
<hitherehowdoyoudo>Hi<hitherehowdoyoudo>

and

<DOYouLikeBananas>banana</DOYouLikeBananas>


If you embed valid HTML tags in undefined tags it does work:

Like this:

<ILikeBananas>
<p>Hello
</ILikeBananas>

Anyway, the problem is not a blank screen. The problem is a JavaScript
runtime error, when I access the method document.getElementsByTagName
("test") it DOES return a DOM node in every browser I have tested in
(including IE). It's only IE that crashes when I try to set the
innerHTML property.
 
G

Gregor Kofler

(e-mail address removed) meinte:
If you embed valid HTML tags in undefined tags it does work:

Like this:

<ILikeBananas>
<p>Hello
</ILikeBananas>

Anyway, the problem is not a blank screen. The problem is a JavaScript
runtime error, when I access the method document.getElementsByTagName
("test") it DOES return a DOM node in every browser I have tested in
(including IE). It's only IE that crashes when I try to set the
innerHTML property.

Does it crash with, say, div, too? If not (which is likely) - what's
your question?

It's kind of FF et all, that they don't crash - it's just that browsers
are so forgiving and try to make sense of the utmost (markup) crap being
served to them. (Is ILikeBananas an inline or block-level element?)

Even when working with valid elements/tags innerHTML has it's issues.
"innerHTML problem" is the search term.

Gregor
 
H

Henry

Not sure I follow.

I mean that hypertext mark-up language does not include a 'test'
element.
There are 2 <test> tags in that HTML document.

There are 4 'test' tags, 2 each of opening 'test' tags and closing
'test' tags. But the document is not HTML as there is no such thing as
a 'test' tag/element in HTML.
This works under Firefox and Safari.

Browsers often tolerate web authors making it up on the spot, but you
still have no reason for expecting it to work, and so shouldn't be too
surprised when you find out where it doesn't.
 
M

marksmith5555

Does it crash with, say, div, too? If not (which is likely) - what's
your question?

OK, I'm trying to do it using a <span> tag now instead. Only,
obviously I don't want all span tags, so I'm using .getElementsByName
instead.

Works under FF. But IE returns an empty list.

<html>
<head>
<script>

function test()
{
var i = document.getElementsByName('image');
i[0].innerHTML='<img src="http://www.google.com/intl/en_ALL/images/
logo.gif">';
}
</script>
</head>
<body onload="test();">
<span name="image"></span>
</body>
</html>
 
G

Gregor Kofler

(e-mail address removed) meinte:
OK, I'm trying to do it using a <span> tag now instead. Only,
obviously I don't want all span tags, so I'm using .getElementsByName
instead.

Spans don't have names.
Works under FF. But IE returns an empty list.

Understandable.

Gregor
 
T

The Natural Philosopher

OK, I'm trying to do it using a <span> tag now instead. Only,
obviously I don't want all span tags, so I'm using .getElementsByName
instead.

Works under FF. But IE returns an empty list.

1/. names strictly apply only to form elements, not to random tags. FF
is kind to you. IE is not, in this respect.

2/. IE7 has a bug where it cannot distinguish between ids and names that
are the same.

so use IDs and getelement by id instead, and make sure with ie, that no
ids are the same as named form elements.



<html>
<head>
<script>

function test()
{
var i = document.getElementsByName('image');
i[0].innerHTML='<img src="http://www.google.com/intl/en_ALL/images/
logo.gif">';
}
</script>
</head>
<body onload="test();">
<span name="image"></span>
</body>
</html>
 
D

David Mark

1/. names strictly apply only to form elements, not to random tags. FF
is kind to you. IE is not, in this respect.

Will you *please* stop repeating that (and other nonsense.) Are you
completely mental?

[snip]
 
M

marksmith5555

so use IDs and getelement by id instead, and make sure with ie, that no
ids are the same as named form elements.

Aren't IDs supposed to be unique?

How should I tag and select a specific group of span elements on a
page?

Thanks
 
G

Gregor Kofler

(e-mail address removed) meinte:
Aren't IDs supposed to be unique?

How should I tag and select a specific group of span elements on a
page?

Traverse the DOM tree "tradionally" with childNodes collections.

Gregor
 
M

marksmith5555

Aren't IDs supposed to be unique?

How should I tag and select a specific group of span elements on a
page?

Thanks

Solved it... Applied a class to all the span elements I wanted.
Selected all span tags, then iterated through them and only did what I
wanted to the ones where className matched the string I wanted...
Works on IE, FF and Safari. Phew! Thanks everybody for your help.
 
T

The Natural Philosopher

Aren't IDs supposed to be unique?

yes, but IE7 searches both name='x' and ID='x' tags when you ask for a
by name or by ID.. and returns the name first IIRC.

How should I tag and select a specific group of span elements on a
page?
by ID.
 

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top