Missing JS file errors with MSIE . Help !!

P

pamelafluente

Hi Guys,

I am trying to include my little script in my html report.
I have done an external JS file which contains it.
If you remember, you have helped me to detect if the asp page was
present by using ajax.
If not present is gracefully stay silent.

The problem is now that when the JS is not present (and it can be) MSIE
gives a lot of errors and one has to kill it.

It starts by saying ROW 1 Character is not valid, Row 1695 Object
Expected and so on...
Firefox does not give any error.

How can I avoid the errors?

Here is a sample of the page: just the first lines:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
.... some styles here ...
</style>

<script language="javascript" src="MenuScript.js"></script>

</head>
<body>
 
I

Ian Collins

Hi Guys,

I am trying to include my little script in my html report.
I have done an external JS file which contains it.
If you remember, you have helped me to detect if the asp page was
present by using ajax.
If not present is gracefully stay silent.

The problem is now that when the JS is not present (and it can be) MSIE
gives a lot of errors and one has to kill it.

It starts by saying ROW 1 Character is not valid, Row 1695 Object
Expected and so on...
Firefox does not give any error.
What, if anything, appears in FF's JavaScript console?
How can I avoid the errors?
By not referring go to stuff that isn't there? You haven't provided
enough information for a decent answer.
Here is a sample of the page: just the first lines:
<script language="javascript" src="MenuScript.js"></script>
Don't use the deprecated 'language' attribute, use 'type'.
 
R

Randy Webb

(e-mail address removed) said the following on 9/26/2006 2:46 AM:

Somebody needs to let the webmaster of that page know that IE7 now has
"tabbed browsing" that it refers to as a benefit of Firefox. And that
the claim:

<quote>
Features like tabbed browsing make reading webpages easier
</quote>

How does having a tab at the top making reading easier?
 
P

petermichaux

Randy said:
(e-mail address removed) said the following on 9/26/2006 2:46 AM:

Somebody needs to let the webmaster of that page know that IE7 now has
"tabbed browsing" that it refers to as a benefit of Firefox.

Whois says

Wilson, Holmes (e-mail address removed)

I'll send him an email.
 
P

pamelafluente

Hi Ian,

most of the other guys here know what I am talking about because they
helped me to write the menu script.

I am not referring to errors occurring within the JS file. The script
is "perfectly" (ahah! ) fine. I am referring to the fact that if the JS
script is not present, MSIE gives a lot of errors.

Some other javascript command (onclick=") are also in the html file.

In any case, I append to this message the comple script and the
essential part of the HTML file. So you are able to get the whole
picture.

In any case thank for the "type" suggestion. I am going to change that.
Any kind of correction is very welcome (watch out for possible line
breaks).



HTML (I removed repetitions that are not necessary)
----------------------------------------------------------------


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8">
<style type="text/css" media="screen">

..c7bg{position:absolute;background:#008000;border-width:1px;border-style:eek:utset;}
..c7fg{position:absolute;border-width:0;color:#ffffff;background:transparent;text-align:center;font-family:Tahoma;font-size:11px;font-weight:bold;}
..c8bg{position:absolute;background:#228b22;border-width:1px;border-style:eek:utset;}
..c8fg{position:absolute;border-width:0;color:#ffffff;background:transparent;text-align:center;font-family:Tahoma;font-size:11px;font-weight:bold;}
..menuItemStyle{
background:#ddeeff;border-width:1px;border-style:inset;font-family:Arial;font-size:11px
}
</style>

<script language="javascript" src="Ajax_Javascript.js"></script>
</head>
<body>

<div id ="RG1,0,0" class=c7bg enabledActions="4,6"
onclick="cellClick(event,this)" onmouseover = "mOver(this)" onmouseout
= "mOut(this)" style="top:170px;left:20px;width:89px;height:30px;">
<div class=c7fg style="top:7px;left:2px;"><table><tr><td width=83px
height=14px valign=middle>SHIPCOUNTRY</td></tr></table></div></div>
<div id ="RG1,0,1" class=c8bg enabledActions="4,2,6"
onclick="cellClick(event,this)" onmouseover = "mOver(this)" onmouseout
= "mOut(this)" style="top:170px;left:112px;width:89px;height:30px;">


<div
style="position:absolute;top:2253px;font-family:Tahoma;font-size:11px;font-weight:bold"><font
color="#c0c0c0">Report generated: <br>lunedì 25 settembre 2006
18.17.59</font><br><a href="http://somesite/"><font
color="#c0c0c0">http://somesite/</font></a><p></p></div>

<form name="form1" method="get" action="ReportProcessor.aspx">
<input type="hidden" name="hiddenFieldName" id="hiddenFieldID"/>
</form>

<div id="menuActions" style="position:absolute; display:none">
<table >
<tr>
<td bgcolor="#eeaa66" style="width: 15px"> </td>
<td id="menuItemContainer"></td>
</tr>
</table>
</div>

</body>
</html>





JS file
-----------------------------------------------------------------

// JScript File: Ajax_Javascript.js

//http://groups.google.it/group/comp.lang.javascript/browse_frm/thread

/b3b8fa7bad9223a4?hl=it
//Laurent Bugnion, GalaSoft

function setStatus( strMessage )
{
// document.getElementById("statusInfo").firstChild.nodeValue =

strMessage;
}

var submitURL;
var oHttp = null;

function submitOnlyIfUrlActive() {

if ( window.XMLHttpRequest ) {
oHttp = new window.XMLHttpRequest();
}
else {
if (window.ActiveXObject ) {
oHttp = new window.ActiveXObject("Microsoft.XMLHTTP" );
}
else {
setStatus("Unsupported Platform");
}
}
if ( !oHttp ) {
setStatus("Error");
}
oHttp.onreadystatechange = submitOnlyIfUrlActiveCallback;
oHttp.open("HEAD", submitURL, true ); // true = async, false =

sync

setStatus( "Checking existence of report processor " + submitURL +

" ...");
oHttp.send( null );
}

function submitOnlyIfUrlActiveCallback() {

if ( oHttp.readyState == 4 ) {
if ( oHttp.status == 200 ) {
document.form1.submit();
}
else {
if (oHttp.status == 404) {
setStatus( submitURL + " Not Found");
}
else {
setStatus("Error: " + oHttp.status );
}
}
}
}

// JScript File: DynamicMenu.js

// onclick on the menuItem return coded info on the action
// and on the cell: MenuItem.id + "," + myCell.id

var menuActions;
var currentCell;
var mouseIsOnCellorMenu;
var previousStyle;

var UserActions=new Array();
UserActions[0]= "DRILL DOWN: include next dimension";
UserActions[1]= "DRILL DOWN this value" ;
UserActions[2]= "DRILL DOWN all values";
UserActions[3]= "DRILL DOWN parent value";

UserActions[4]= "ROLL UP: exclude next dimensions";
UserActions[5]= "ROLL UP this value";
UserActions[6]= "ROLL UP all values";
UserActions[7]= "ROLL UP parent value";

document.onmousedown = mMouseDownOnDoc;

function cellClick(event, myCell) {

currentCell = myCell;

if (myCell.id != null) {

var flags = myCell.getAttribute("enabledActions");
menuActions = document.getElementById("menuActions");
var actionCodes = flags.split(",")

var menuItemContainer =

document.getElementById("menuItemContainer");
menuItemContainer.innerHTML = "";
for ( var i = 0; i < actionCodes.length; i++ ) {
var actionCode = parseInt(actionCodes)

menuItemContainer.innerHTML += "<div id=" + actionCodes

+
" class=menuItemStyle" +
" onmouseover='mOverMenuItem(this)'

onmouseout='mOut(this)' onclick='mClick(this)'>" +
" &nbsp " + UserActions[actionCode] + "

&nbsp</div>"
}
if (event == null) event = window.event;
var scrollTop = document.body.scrollTop ?

document.body.scrollTop : document.documentElement.scrollTop;
var scrollLeft = document.body.scrollLeft ?

document.body.scrollLeft : document.documentElement.scrollLeft;
menuActions.style.left = event.clientX + scrollLeft + 'px';
menuActions.style.top = event.clientY + scrollTop + 'px';
menuActions.style.display = 'block';
}
}

function mMouseDownOnDoc() {
if (!mouseIsOnCellorMenu) {
if (menuActions != null) {
menuActions.style.display = 'none';
}
}
}

function mOver(MyDiv) {

menuActions = document.getElementById("menuActions");
if (menuActions == null) {return} //in case page still

loading

mouseIsOnCellorMenu = true;

if (currentCell != MyDiv) {
menuActions.style.display = 'none';
currentCell = MyDiv;
}

if (previousStyle == null) {
previousStyle = MyDiv.style.backgroundColor;
MyDiv.style.backgroundColor = "#ffff00";
}
}


function mOverMenuItem(MyDiv) {

mouseIsOnCellorMenu = true;

if (previousStyle == null) {
previousStyle = MyDiv.style.backgroundColor;
MyDiv.style.backgroundColor = "#ffee22";
}
}

function mOut(MyDiv) {

mouseIsOnCellorMenu = false;

if (previousStyle != null) {
MyDiv.style.backgroundColor = previousStyle;
previousStyle = null;
}
}

function mClick(menuItem) {

alert("Clicked " + menuItem.id + "," + currentCell.id );

var hiddenField = document.getElementById("hiddenFieldID");
hiddenField.value = menuItem.id + "," + currentCell.id;
submitURL = document.form1.action;
submitOnlyIfUrlActive();
}








Ian Collins ha scritto:
 
P

pamelafluente

I do not know how to deal with the error due to missing reference to JS
file, but

let's begin to try cut some errors in the body (which are the largest
number)


for instance:

onclick="cellClick(event,this)"

can I transform this in:

if cellClick is not nothing then cellClick(event,this) ??

if yes, what would be the correct way to do that ?

-P
 
I

Ian Collins

I do not know how to deal with the error due to missing reference to JS
file, but

let's begin to try cut some errors in the body (which are the largest
number)


for instance:

onclick="cellClick(event,this)"

can I transform this in:

if cellClick is not nothing then cellClick(event,this) ??

if yes, what would be the correct way to do that ?
Why not just add all your event handlers to the DOM in onload()? That
way you won't have any references to a script that isn't there.
 
P

pamelafluente

Ian Collins ha scritto:
Why not just add all your event handlers to the DOM in onload()? That
way you won't have any references to a script that isn't there.

Hmmm.
This seems a really good idea.

[It will left open the reference problem, but let's see a problem at a
time.]


Ok I have several DIVs which look like this:

<div id ="RG1,0,0" class=c7bg enabledActions="4,6"
onclick="cellClick(event,this)" onmouseover = "mOver(this)" onmouseout
= "mOut(this)" ...

Not all DIVs will have handlers attached. But I guess I could put a
special attribute to the DIVs where the handlers have to be attached.

Ok, now assume I identify the DIVs with handlers attached by an extra
attribute, eg. hasHandlers:

<div id ="RG1,0,0" class=c7bg enabledActions="4,6" hasHandlers="True"

how would I add dynamically the following handlers on load to these
DIVs ?

onclick="cellClick(event,this)"
onmouseover = "mOver(this)"
onmouseout = "mOut(this)"


-P
 
I

Ian Collins

Ian Collins ha scritto:

Why not just add all your event handlers to the DOM in onload()? That
way you won't have any references to a script that isn't there.


Hmmm.
This seems a really good idea.

[It will left open the reference problem, but let's see a problem at a
time.]


Ok I have several DIVs which look like this:

<div id ="RG1,0,0" class=c7bg enabledActions="4,6"
onclick="cellClick(event,this)" onmouseover = "mOver(this)" onmouseout
= "mOut(this)" ...

Not all DIVs will have handlers attached. But I guess I could put a
special attribute to the DIVs where the handlers have to be attached.

Ok, now assume I identify the DIVs with handlers attached by an extra
attribute, eg. hasHandlers:

<div id ="RG1,0,0" class=c7bg enabledActions="4,6" hasHandlers="True"
I'd prefer a unique class.
how would I add dynamically the following handlers on load to these
DIVs ?

onclick="cellClick(event,this)"
onmouseover = "mOver(this)"
onmouseout = "mOut(this)"
Just add them to the elements, this is well documented in any JavaScript
text.
 
W

web.dev

Ok I have several DIVs which look like this:

<div id ="RG1,0,0" class=c7bg enabledActions="4,6"
onclick="cellClick(event,this)" onmouseover = "mOver(this)" onmouseout
= "mOut(this)" ...

Your id consists of characters that make it invalid.

url: http://www.w3.org/TR/html4/types.html#type-name

It is also generally good practice to place quotes around all values.
<div id ="RG1,0,0" class=c7bg enabledActions="4,6" hasHandlers="True"

how would I add dynamically the following handlers on load to these
DIVs ?

onclick="cellClick(event,this)"
onmouseover = "mOver(this)"
onmouseout = "mOut(this)"

For your event handlers, you don't need to pass "this", because that's
the context it's already being executed in. For the onclick, event
will automatically be passed in (for non-IE browsers), so you'll have
to handle it yourself.

Assuming you have corrected your id name to something like "RG100", you
can do something like the following:

javascript:

<script type = "text/javascript">
function cellClick(ev)
{
if(!ev)
{
var ev = window.event; //for IE
}
}

function mOver()
{
//example
this.style.backgroundColor = "red";
}

function mOut()
{
//example
this.style.backgroundColor = "blue";
}

function init()
{
var elem = document.getElementById("RG100");
elem.onclick = cellClick;
elem.onmouseover = mOver;
elem.onmouseout = mOut;
}

window.onload = init;
</script>

html:

<div id = "RG100" class = "c7bg">etc</etc>
 
P

pamelafluente

Thanks Ian and Thanks web.dev !!


web.dev ha scritto:
Your id consists of characters that make it invalid.
Thanks for that observation. It "works", but I was wondering if am
using illegal chars.
Is it fine to replace the "," with "hyphens "-" ? Or do you have
better suggestion
(I process that with a split() function) ?
url: http://www.w3.org/TR/html4/types.html#type-name

It is also generally good practice to place quotes around all values.

I guess you are referring to the class name. Right?
class="c7bg"

On that I have a general question. I noticed that this works with any
browser. In such
a cases, where it is clear that it works, is it better to quote
anyway, or it is preferible
ro save chars. After all I can have literally thousands of those DIVs
and it's 2 additional chars " ... " for each DIV. That can make the
stream quite bigger.

What is your general advise on that ?
For your event handlers, you don't need to pass "this", because that's
the context it's already being executed in. For the onclick, event
will automatically be passed in (for non-IE browsers), so you'll have
to handle it yourself.

This, I guess, may be incorrect. Unless I am not getting your meaning.

"This" here represent the current DIV. There may be thousands of
them.
Perhaps you are assuming I intend to refer to the document or I am
getting the wrong
meaning ?
Assuming you have corrected your id name to something like "RG100", you
can do something like the following:

javascript:

Thanks a lot for the code. Perhaps I did not made clear that I have
thousands of those DIVs so I need to find them all and attach an
handler to them.

I will try to adapt your code and post it so you can advise me.

Finally about the refenced JS file. Is there anything I can do to avoid
the error due to missing file ?


-P
 
I

Ian Collins

Thanks Ian and Thanks web.dev !!


web.dev ha scritto:



Thanks for that observation. It "works", but I was wondering if am
using illegal chars.
Is it fine to replace the "," with "hyphens "-" ? Or do you have
better suggestion
(I process that with a split() function) ?
It appears to work on the current browsers you have tried. It might not.

Use http://validator.w3.org/ to sanitise your markup.
I guess you are referring to the class name. Right?
class="c7bg"

On that I have a general question. I noticed that this works with any
browser. In such
a cases, where it is clear that it works, is it better to quote
anyway, or it is preferible
ro save chars. After all I can have literally thousands of those DIVs
and it's 2 additional chars " ... " for each DIV. That can make the
stream quite bigger.

What is your general advise on that ?
See above.
This, I guess, may be incorrect. Unless I am not getting your meaning.

"This" here represent the current DIV. There may be thousands of
them.
Perhaps you are assuming I intend to refer to the document or I am
getting the wrong
meaning ?
Read up on events, either in standards based browsers, or IE, you can
access the target element form the event.
Finally about the refenced JS file. Is there anything I can do to avoid
the error due to missing file ?
What error?
 
P

pamelafluente

Ian Collins ha scritto::

Thank you Ian
Use http://validator.w3.org/ to sanitise your markup.

I will
Read up on events, either in standards based browsers, or IE, you can
access the target element form the event.

Hmmm you mean like the "sender" argument in VS ? I have to look up that
....
What error?

I believed that the first error was due to:

<script type="text/javascript" src="Ajax_Javascript.js"></script>

but perhaps I am wrong ?


-P
 
P

pamelafluente

Ian Collins ha scritto:

Let's see an example.
Take for instance

function mOverMenuItem(MyDiv) {

mouseIsOnCellorMenu = true;

if (previousStyle == null) {
previousStyle = MyDiv.style.backgroundColor;
MyDiv.style.backgroundColor = "#ffee22";
}
}

If I want to rewrite it as:

function mOverMenuItem() {
// function without sender argument

var MyDiv = ??

}

how would I access the object which was called "MyDiv" within this
(function
without sender argument) ? (I need it work with IE anf FF at least.)



And will it work with the other functions too?

onclick="cellClick(event,this)"
onmouseover = "mOver(this)"
onmouseout = "mOut(this)"
....


-P

--
 
P

pamelafluente

Ian Collins ha scritto:
(e-mail address removed) wrote:
I'd prefer a unique class.
what does this mean? I have for instance class=c7bg.
This is a style applied to that cell (div). Each DIV can have a
different style (there are some dozen styles defined).
Not all DIV with a given style have handlers attacched.

What would be in practice your suggestion? It seems I have already a
class defined. Can I define multiple classes?

-P

--
 
W

web.dev

Hmmm you mean like the "sender" argument in VS ? I have to look up that
...

In the sample code that I provided to you earlier, you'll notice that I
have not sent "this" to the function, instead the function already has
a concept of "this". Therefore you can already use "this" within the
function. For the case of the click, the browser will send an event to
your function, thus you don't have to send it yourself.
I believed that the first error was due to:

<script type="text/javascript" src="Ajax_Javascript.js"></script>

but perhaps I am wrong ?
From your posts, I have come to the conclusion that the "missing file"
error is not at all that. It's only half the problem. In your html
you appear to have many inline javascript. So when you are missing the
necessary javascript file, you'll get an error when for example you
attempt a "cellClick". This is because it will try to invoke the
javascript you have placed inline, but the javascript that is in your
external file is missing.

This is what we've been trying to help you with. Instead of inlining,
you will instead dynamically assign your event handlers.
 
P

pamelafluente

web.dev ha scritto:
This is what we've been trying to help you with. Instead of inlining,
you will instead dynamically assign your event handlers.

yes web.dev exactly. Thanks
(There is a whole thread on dynamically attaching the handlers. Do not
know if for some reason you cannot see the messages from Laurent, Ian,
Duncan, Richard, myself...)


To ALL
==========

Ok finally dinamic handlers work with FF too.

Laurent was definitely right about the event argument in Function() [
he is always right :)) ].

Actually, I do not have the slightest idea why this is working and why
only for Firefox it is necessary to pass that event argument in such a
way.

I leave explaining this to Laurent, or anyone willing to enlight us
about that ... To me all this mechanism seems quite misterious at this
"beginner" time...

javascript will never finish to surprise me ....

-P
 
D

Dr John Stockton

JRS: In article <[email protected]>,
dated Tue, 26 Sep 2006 23:54:01 remote, seen in
news:comp.lang.javascript, (e-mail address removed) posted :
Finally about the refenced JS file. Is there anything I can do to avoid
the error due to missing file ?

If the file contributes anything even slightly useful to the page, and
is missing, then there will inevitably be some sort of error on the page
- even if only diminished beauty.

But, if you put var RhubarbJS = 1 at the end of included file
rhubarb.js, then in mainpage.htm you can test whether RhubarbJS is set,
and if it is not you can refrain from trying to use the other contents
of rhubarb.js.

I do such a test in all(?) of my JS-using Web pages.


Alternatively, test for the existence of anything in rhubarb.js just
before using it.
 

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,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top