I started to test my web site on google chrome and
'cannot call method 'join' of null'
appears when doing this:
var sChoices = oQuestion.aChoiceRand.join("");
In IE and FF works well. What I'm trying to do with this code is to join all the aChoiceRand array elements in a string without any separators. How can I solve this?
The problem's cause must be earlier, when oQuestion.aChoiceRand gets assigned: you think it's assigned to an array (and apparently IE and FF agree with you), Chrome is telling you that it's null instead. We can't really help without seeing the code that's supposed to assign oQuestion.aChoiceRand its value...
Related
The object {'1':'test'} gives an error in Firefox, but seems to be fine in Chrome. Does anyone know how to get around this error and make this work? The keys and values are from an external source so I can't just change them. (Run the code snippet below in Firefox and you will see the error.)
{'1':'test'}
You have to save the object in a variable or use it in any way. Just writing in inside a script block does nothing.
The following works fine:
var obj = {'1':'test'};
alert(obj['1']);
I tried in chrome console and firefox console.
Indeed, that doesn't work in Firefox, but, it's normal.
In javascript you can't type JSON without variable declaration before.
So, Firefox doesn't understand it because javascript doesn't understand it.
In fact, I think that Chrome overrides the javascript interpretor to allow declaration without attributions.
Like in python shell when you type 5, it will write 5. So with that Chrome allow you to see the structure of an array or object whatever, just by typings them without declare it into a variable.
You can see an example here :
https://jsfiddle.net/3yqdj599/
let yes = {'1':'test'};
console.log(yes)
// {'1':'test'} => that doesn't work
Finally, don't worry, since a browser is able to execute javascript, if you assign your object in a variable, it will interpret it.
I hope this is clear and helped you ! :)
Cya !
I'm developing a page with the following libraries;
jQuery (1.7.2) (older version because of a dependency issue, but have tried up to 1.9.1, doesn't fix issue).
Backbone (1.1.0)
lodash (2.4.1)
modernizr (2.7.1)
gsap (1.17.0)
The page use canvas and gsap for animation. Everything works great in IE11, Chrome, Safari, Firefox, and IE8 (animations disabled for IE8), but IE9 and 10 just throw this error in the console over and
unable to get property 'replace' of undefined or null reference
The line referenced is in jquery.js, line 622, which is the return statement in this code:
// Convert dashed to camelCase; used by the css and data modules
// Microsoft forgot to hump their vendor prefix (#9572)
camelCase: function( string ) {
return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
},
I can't figure out how to determine what part of MY code caused this jQuery code to fire, so I'm unsure as to what may be the issue on my end.
Does anyone know a fix for this? Or alternatively, how I can view what part of my code caused this jquery code to fire (using IE dev tools)?
Turns out the issue wasn't something inherently wrong with IE, but rather I was trying to access an object which didn't entirely exist yet. The other browsers this was not an issue (perhaps their JS engines were just fast enough for it to be a non-issue), but I've now added checks to ensure all the relevant content has loaded before executing the problematic function and the issue seems to be gone. Thanks for the help, all.
What kind of tool are you using for debugging? I have a solution for you for Chrome debug console
1. First go Find the jquery script file in the console, right click and select "Blackbox script" it is going to be ignored while debugging, only your files are going to be considered
2. Activate break on errors and a breakpoint is going to be triggered on the line of code where the exception is occurring
Check JavaScript: Is there a way to get Chrome to break on all errors?
and https://developer.chrome.com/devtools/docs/blackboxing
Maybe I'm wrong here but is it possible that IE8-9 "string" is a reserved word? Maybe not. But the only time .replace would show that message is if you were not feeding it a string.
camelCase: function( string ) {
if(!string){
console.log("string is falsy", string);
return string;
}
return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
},
TypeError: Unable to get value of the property 'childNodes': object is null or undefinedundefined
After making a long list of modifications to my application in order to support IE8, including:
running all of the views in their compiled form through W3C validator, setting up xdomain.js proxy to support CORS API calls, making some general restructures, etc.
I was very disappointed to find out that IE8 still throws this weird error at me, while IE9 works perfectly fine.
Making changes to the Angular-seo package to prevent it from running when the client is an IE browser.
Any ideas on what can it be?.
Make sure that all your tags are closed properly. I just spent hours trying to figure out what the problem was, until I noticed this in my code:
<span>some text<span>
I finally realized I didn't close the <span> tag properly. After that everything just worked.
Without the code you are running it is a bit difficult. However there is a command to use for debugging. First you need to identify which variable might not contain an object [i.e.
"object is null or undefined"].
For example, parent, then you can use
//next look to see if parent is something
if('undefined'==(typeof parent)) alert("variable empty:parent");
Once you find something that is empty that you are expecting to be an object then you can go trace back from there. Also use a browser debugged tool, to identify the line number of the error.
Often if using the child nodes, you may not have the right level or you need to access as an array i.e. you need something like.
parent.childNodes[0].childNodes[0].value
In IE you are also dealing with unsupported functions. So getElementById will work but some other similar ones do not. Again typeof can be useful.
//next ensure function supported
if( 'undefined'==(typeof document.getElementsByClassName) ){
alert("Not Supported"); // notice ^ no () required here
//...add code to handle differently when not supported
}
This may reveal if you can use a function
IE8 is so old and non-standards compliant it doesn't support childNodes[]. http://quirksmode.org/dom/core/#t70
I'm having a problem with an ajax script that checks postcodes against a region table in the database to find which area the postcode relates to, then updates the region select list with this information.
There's nothing wrong with the ajax scripting at all, because it works from another page just fine. A particular page (in an admin area I can't give access to) is having problems and my debugger says "Uncaught TypeError: Cannot read property 'length' of null" when the call to the remote script is triggered.
I'm baffled by it, because I'm clueless as to what it's suggesting is null. I understand what it's saying, that it can't read the length of null, obviously, but I can't see what it could be that's null. It may be being given an empty string, but an empty string doesn't trigger this error on the other pages, and an empty string isn't null.
I know I've not given much to go on, but if you could offer any more debugging advice, it'd be great.
Thanks.
Peter Olson's suggestion was great, I've since explored and discovered lots of powerful debugging tools built into Chrome (I'm sure Firebug, etc, have the same stuff).
It turned out to be that a script used getElementById on an element that didn't have an Id. Hence why the script worked fine on the other pages (the inputs on the other pages had IDs)
I've fixed the problem now.
Thanks a lot.
i have problem obtaining globalPagefrom safari.extension inside injected script.
Every time i try to get it safari returns error in console:
TypeError: Result of expression 'safari.extension.globalPage' [undefined] is not an object.
Inside Global Page script i don't have problem obtaining it.
Does any one of you know how to resolve this issue ?
Thanks
You can't directly access globalPage from an injected script; you have to use message passing to access any globalPage objects. Read this section of the Safari Extensions Dev Guide. Comment if you need tips.