WinVista/IE7
I am getting some weird errors only in IE7, but not in FF2.0.0.8 or NN9. It even happens on this website when I click "Sign In". The error is:
"A Runtime Error has occurred."
"Line:xxx"
"Error: Object expected"
and Debug says: "Microsoft JScript runtime error: Object expected."
The line in my code that debug points to is:
I guess there is something fundamentally different between how JScript and Javascript behave (duh!), but I just cannot figure out what is wrong.
The code is relatively simple. "loadDiv(id)" simply creates a 'div' element in 'document.body' with an id, as you would expect, of object "id". What could be simpler? But to be sure, here is my loadDiv() code: -
function loadDiv(id)
-
-
{
-
-
var elemDiv = document.createElement('div');
-
-
elemDiv.id = id;
-
-
document.body.appendChild(elemDiv);
-
-
};
-
Like I said, very simple. Perhaps I need to do this a different way. Does IE prefer the code like this instead: -
function loadDiv(id)
-
-
{
-
-
var elemDiv = document.createElement('div');
-
-
elemDiv.setAttribute("id", id);
-
-
document.body.appendchild(elemDiv);
-
-
};
-
Is one way better than another?
Thanks.
10 13272
WinVista/IE7
I am getting some weird errors only in IE7, but not in FF2.0.0.8 or NN9. It even happens on this website when I click "Sign In". The error is:
"A Runtime Error has occurred."
"Line:xxx"
"Error: Object expected"
and Debug says: "Microsoft JScript runtime error: Object expected."
The line in my code that debug points to is:
If that is definitely the line, then it can only mean that the function is undefined. Are you sure there's nothing in the Firefox console?
hi
I have test your function "loadDiv" in firefox and IE7, it's fine.
I think the problem is "loadDiv("divlogin");". the browser can't find loadDiv funcion.I think you need to provide more code.
by the way,I guess there should have an error in firefox.firefox will not alert an error message,and the error message will be saved in "Error Console".you can check it in "tool"->"Error Console".
I've been running Firebug. No errors reported in FF at all. But I think I know what the problem is.
I am using addEvent to initiate my external scripts including my loadDOM.js script, which has my loadDiv() function in it, and any function called by addEvent too soon doesn't find it defined. If I wait and run loadDiv say with an onclick="" attrib, it works. So this is a timing issue...I'm firing off loadDiv() commands too soon.
So I suppose I need to add a conditional if(loadDiv) or put my loadDOM code into my loadInit.js file rather than call it from addEvent. Dunno, have to consider this a bit.
Thanks for your replies!
hi
I don't think you need to change the code in loadDiv because you didn't recieve any error message in Firefox.I guess maybe you used "addActionListener" to add an event to your button. or maybe you can just move your functions in the right position. -
<html>
-
-
<head>
-
function loadDiv....
-
function load2....
-
</head>
-
-
<body>
-
<input type = "button" id="btn" .../>
-
</body>
-
-
function addEvent()
-
{
-
loadDiv();
-
load2();
-
....
-
}
-
-
document.getElementById("btn").onclick = addEvent;
-
<html>
-
hope it helps.
Thanks Ferris, and yes, addEvent() does use addEventListeners, but I don't load any code in my HTML except a link in HEAD to my loadInit.js file. Additionally, all my scripts are broken up into different files in order to reduce bandwidth needs and speed up response time (on-demand javascripts). So really, my problem is much more complicated than I made it out to be. Here's the basic structure of my site:
Single webpage:
HTML calls loadInit.js file, which contains addEvent() functions.
loadInit.js calls all my other scripts using addEvent() for onload, onunload, etc.
Some of my scripts are:
loadDOM.js - contains all my DOM element creation and removal functions.
loadXHR.js - contains my XMLHttpRequest functions.
loadLogin.js - contains my login verification and processing functions. This is where my problem is at the moment.
So either my loadDOM functions are not being loaded into the global space where my other functions can access them, or my other functions like those in loadLogin are loading too quicky / too early before loadDOM is loaded. I am working on testing this now by manually initiating loadLogin with an onclick="" after the page loads (loadDOM runs at window onload at the moment).
I don't know if my addEvent functions initiate in the order they are listed. I need to research that. It's not my code.
I should add that my addEvent function does far more than just control the adding of events. It controls the the browser cache as well to address memory leaks in IE through a removeEvent function and an EventCache function. I can always post the script here if you are interested in seeing it. It's called "Rock Solid addEvent()".
Because addEvent does more than just load up scripts after the page has loaded, I don't know how it affects the loading of functions and vars into global space.
Hi
it sounds complicated..
but if the addEventListener remain in your code,your code will never be correct in IE,because addEventListener is only supported in Firefox,not in IE.
you can try to change addEventListener into some other code,for example
document.getElementById("btn_ok").addEventListener ('click',func,false);
->
document.getElementById("btn_ok").onclick=func;
if the error still exsist, it is really complicated..
hope it helps. :)
At the moment, I have stopped using Add Event until I get all my independent scripts working, which I almost have. Once I do that, I will reintroduce Add Event.
In the meantime, here's the first part of the Add Event script, which doesn't include the removeEvent() or EventCache() functions. As you can see, the code forks depending on the browser's capabilities: -
function addEvent(obj, type, fn)
-
-
{
-
-
if (obj.addEventListener) // FireFox, NN, Mozilla, etc.
-
-
{
-
-
obj.addEventListener(type, fn, false);
-
-
// bugzilla bug #241518
-
-
EventCache.add(obj, type, fn);
-
-
}
-
-
else if (obj.attachEvent) // MSIE
-
-
{
-
-
var func = function()
-
-
{
-
-
fn.apply(window.event.srcElement);
-
-
};
-
-
obj.attachEvent("on" + type, func);
-
-
EventCache.add(obj, type, func);
-
-
}
-
-
else if (typeof obj['on' + type] != 'function')
-
-
{
-
-
obj['on' + type] = fn;
-
-
}
-
-
else // really old
-
-
{
-
-
var oldonload = obj['on' + type];
-
-
obj['on' + type] = function()
-
-
{
-
-
oldonload();
-
-
fn();
-
-
};
-
-
};
-
-
};
-
And just in case anyone is interested (for you code junkies out there who get all excited just over the chance at looking over code), here is the rest of the Rock Solid addEvent() script:
By the way, a question: can anyone explain to me the reason for the ' (); ' at the very end? You can read more about the original code on Mark Wubben's Site. -
function removeEvent(obj, type, fn)
-
-
{
-
-
EventCache.remove(obj, type, fn);
-
-
};
-
-
-
var EventCache = function()
-
-
{
-
-
var listEvents = [];
-
-
return {
-
-
listEvents : listEvents,
-
-
add : function(node, sEventName, fHandler)
-
-
{
-
-
listEvents.push(arguments);
-
-
},
-
-
remove : function(node, sEventName, fHandler)
-
-
{
-
-
var i, item;
-
-
for(i = listEvents.length - 1; i >= 0; i = i - 1)
-
-
{
-
-
if(node == listEvents[i][0] && sEventName == listEvents[i][1] && fHandler == listEvents[i][2])
-
-
{
-
-
item = listEvents[i];
-
-
if(item[0].removeEventListener)
-
-
{
-
-
item[0].removeEventListener(item[1], item[2], item[3]);
-
-
};
-
-
if(item[1].substring(0, 2) != "on")
-
-
{
-
-
item[1] = "on" + item[1];
-
-
};
-
-
if(item[0].detachEvent)
-
-
{
-
-
item[0].detachEvent(item[1], item[0][sEventName+fHandler]);
-
-
};
-
-
item[0][item[1]] = null;
-
-
};
-
-
};
-
-
},
-
-
flush : function()
-
-
{
-
-
var i, item;
-
-
for(i = listEvents.length - 1; i >= 0; i = i - 1)
-
-
{
-
-
item = listEvents[i];
-
-
if(item[0].removeEventListener)
-
-
{
-
-
item[0].removeEventListener(item[1], item[2], item[3]);
-
-
};
-
-
if(item[1].substring(0, 2) != "on")
-
-
{
-
-
item[1] = "on" + item[1];
-
-
};
-
-
if(item[0].detachEvent)
-
-
{
-
-
item[0].detachEvent(item[1], item[2]);
-
-
};
-
-
item[0][item[1]] = null;
-
-
};
-
-
}
-
-
};
-
-
}();
-
Hi
I think there's no problem in your event code...
Good to hear, thanks Ferris. Once I get all the kinks out of my scripts, I will go back and try to initiate them with addEvent() and see what happens.
By the way, I confirmed with the script's co-creator that in the current script there is no way to force addEvents to load in any particular order. So I guess I will have to come up with a way to do it...perhaps as simple as one script calls the next, or one script has to wait on the one before it to complete loading before firing off. I dunno, still have to think some more on this.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Danny |
last post by:
Hi I don't understand why I keep getting "Error: Object expected" I
tried different things and haven't been able to solve it. I'm a newbie
so I'm not sure what I'm doing wrong. The debugger breaks...
|
by: theroo |
last post by:
Hi there,
I am driving myself crazy over this problem.
I have used this very same function in another page without any
problems, but now I am experiencing the "Error: Expected ';'" when i
try...
|
by: STAGED |
last post by:
The script:
proc bugsy { } {
global helmet
pack forget .widget1
if { $helmet(key1) } {
pack .widget2 -anchor nw -side top -expand 0
} else { show_new_widget }
|
by: Steve Chapel |
last post by:
When I load the page
<https://bugzilla.mozilla.org/attachment.cgi?id=237739with Internet
Explorer 7 RC 1, I get the error "Object Expected" at line 174. When I
click on the button, I also get the...
|
by: monudjn |
last post by:
Hi I am implementing ajax in portal. Using ajax i am able to updating the content of portlets asynchronously. However i am facing a problem
The Problem: While submitting the form i am getting...
|
by: Lawrence Spector |
last post by:
I ran into a problem using g++. Visual Studio 2005 never complained
about this, but with g++ I ran into this error. I can't figure out if
I've done something wrong or if this is a compiler bug. ...
|
by: Diego Ruiz |
last post by:
Hi!! my english is not too good, but i'll try it
I have a javascript code:
function executeCommands(inputparms)
{
// Instantiate the Shell object and invoke
its execute method.
...
|
by: thj |
last post by:
Hi.
I've got this form that I'm trying to validate:
<form id="periodForm" action="" method="post">
<p>
Periode:
<input id="startDate" name="startDate" type="text" size="7"
value="<%=...
|
by: Rohit |
last post by:
I am trying to initialize an array whose initializers depend on value
of Enums. I take enum and then decide the initializer value, so that
even if enum value changes because of addition to list...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |