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 13295
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("divlo gin");". 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 "addActionListe ner" 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 addEventListene rs, 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 addEventListene r remain in your code,your code will never be correct in IE,because addEventListene r is only supported in Firefox,not in IE.
you can try to change addEventListene r into some other code,for example
document.getEle mentById("btn_o k").addEventLis tener('click',f unc,false);
->
document.getEle mentById("btn_o k").onclick=fun c;
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...
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 at the
<BODY> Tag of my code so I'm thinking the problem is with my
InitPage() function. I appreciate the advice. Here is my code.
<SCRIPT...
|
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 and run it, and it doesn't fire (obviously, because there is an
error).
The code is:
|
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 same error on line 186. This same
HTML and JavaScript works perfectly in Firefox and Opera. How can I make
the code work in IE?
|
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 javascript error " Object expected". These errors i am getting after implementing ajax. Also this error is shown only the first time i trying to submit....
| |
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. Here's a very
simple example which should illustrate what I'm doing.
#include <iostream>
template <class T>
class TestBase
{
|
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.
var oShell = new ActiveXObject("Shell32.Application");
|
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="<%= ViewData %>" />
-
|
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 even then I
should be able to get correct value for the array element. I need
value and state to be present in a single byte thats why I use macros.
...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |