I've never seen this error. We have some clients that use Internet Explorer 6, so we need some pages to work on it.
We have the following HTML code:
<script type="text/javascript">
var bust = 236;
</script>
IE6 is throwing the following error message: 'Undefined' is null or not an object.
Do you have any idea what it might be?
Thanks.
It sounds like bust is conflicting with some other global. The global name space is really crowded.
You may be able to resolve it by wrapping your code in a scoping function so that it's not at global scope anymore:
<script type="text/javascript">
(function() {
var bust = 236;
})();
</script>
Or if it has to be a global, try another name until you find one that doesn't cause the problem. Global variables aren't fundamentally broken, even in IE6.
Related
Is it possible to have a global reference only be available from a JS
console, but not available to other JS running on a page?
For example, could I set a variable m to 10, so that...
<script>
console.log(m);
</script>
Is a ReferenceError, but from the console...
console.log(m);
Prints 10?
Edit:
The responses so far only touch on the basics of scope in JavaScript, but if this is possible, it's going to be way more hacky than adding a variable to a scope that only the console can see (yes, I know this doesn't exist). Here's an almost-working example of what I'm looking for:
Object.defineProperty(
window,
"m",
{
get : function window_m_getter() {
if (CONSOLE_OPEN) {
return 10;
} else {
throw new ReferenceError('m can only be used in a console');
}
},
}
);
This example would work if it were possible to detect whether the console was currently open, which it really isn't, but it's pretty close.
The answer to this question is almost certainly no, but it isn't entirely because of scope.
No.
The developer console operates in the global namespace. It's the same one every script uses, hence the name. There is no private, different namespace for the console.
The very console object you are accessing to log() is part of this namespace, and thus available to everyone.
At most, you can declare global variables for the console after you've loaded all of your scripts, at the very end of the <body>, making them unavailable until after everything runs. This, however, won't stop scripts from accessing them afterwards, from triggered events.
I have created an ASP.Net application. I am using a javascript which is written in a separate file. I am using Var myvariableName ={} in javascript file.
I have included this file in MasterPage and accessing myvariableName in my aspx page.
This is working fine in Google Chrome, however, in IE 8 an unhandled exception is thrown as
myvariableName is undefined.
the error shows as;
0x800a1391 - Microsoft JScript runtime error: 'Common' is undefined
where Common is my javascript variable.
Please assist me in resolving this issue.
You're probably accessing the variable before your external script is executed.
Be sure to access your variable as soon as the document is fully loaded (i.e. $(document).ready(function(){...}); if you use jQuery) or try to find out the real execution order with some alert (that shouldn't be browser-depentent, by the way!).
If your code is already in a document.load or $(document).ready(function) you can always
handle the variable before acessing it via
if (typeof myvariableName !== "undefined") {
// do stuff
}
Some times in IE shit happens and window.load gets screwed specially when async calls are in place.
You are probably getting this error due to a missing semicolon. Change the code to this:
var myvariableName = {};
In your asp page, where you access your custom variable, wrap your code with:
var myvariableName = {};
window.onload = function(){
// your code here where you're accessing the variable
};
I'm kind of new to this so a bit confused.
I have a js file named rrr.js, in which I have this code:
var rrr_rrr2=
{
// get the domain name from the current url
get_domain_name:function()
{
//code here...
},
// other functions here
}
Now in my HTML page I simply added it like I usually do:
<script type="text/javascript" src="rrr.js">
and called it like this:
Step 1 completed!<br><br>Click here
But that does not work... what am I doing wrong?
(by the way, this is in a firefox addon. FF gives me this error:
Error: rrr_rrr2 is not defined
Source File: javascript:rrr_rrr2.get_domain_name()
Line: 1
Help please!
I think Satyajit was almost right. Try closing it like this instead:
<script type="text/javascript" src="rrr.js"></script>
But also, if this js file is part of your addon, you can't access it directly from an HTML page, unless you put it at a resource: URI or something. Read up on privileged vs. unprivileged code.
Could it be that you have not closed the tag like so
<script type="text/javascript" src="rrr.js"**/**>
Nothin is wrong with the code you have just shown, I have reproduced it in this JsFiddle.
There is one thing to look out for: the variable rrr_rrr2 must be in the global scope to access it with the javascript: href. If it is defined inside of a function, for example, then it is not in the global scope and cannot be accessed.
The JavaScript script works with Chrome and Firefox but not in Safari. The code is:
$(document).ready(function(){
$(window).load(function() {
myVariable.start();
});
This generates:
ReferenceError: can't find variable: myVariable
The variable is defined in another JavaScript page that is included in this page, but for some reason Safari doesn't see the definition in the other page. Is Safari executing this script without loading the page that the variable is defined in?
How can I fix this?
Thanks for any help
Try to avoid setting global variables.
Maybe try assigning your variable to the window object, on top of the page:
window.myVariable = { start: function() {} };
Then when you need it:
$(window).load(function() {
window.myVariable.start();
});
I'm using a global variable in javascript, declared in a script tag outside any function:
<script type="text/javascript">
var prov_status_dict={};
....
</script>
Later on in a javascript method I'm using the variable normally.
temp=prov_status_dict[current_as_id];
I'm having issues with it on opera and ie, while on firefox it works. This is what opera's error console reports:
JavaScript - http://localhost:8000/input/
Event thread: click
Error:
name: ReferenceError
message: Statement on line 62: Undefined variable: prov_status_dict
stacktrace: n/a; see opera:config#UserPrefs|Exceptions Have Stacktrace
I've noticed that the problem is with global variables in general. I tryed moving some into hidden fields, but the same error pops up on the next use of a global var.
Help?
I usually access my globals through the window object so that I always have a point of reference
window.MyVariables = {};
window.MyVariables.prov_status_dict = {};
Give this a try, it might resolve your problem.
Try to avoid using global variables, see http://yuiblog.com/blog/2006/06/01/global-domination