Yet another reason why I hate IE for being different. I've got this code:
var friends = document.getElementById('friendsEmail').value; ... var emailArray=new Array(); emailArray=String(friends).split(','); //error here
This works in every other browser. In fact I only added the
Array declaration and the explicit
String conversion to get this to work in IE. However, I'm still getting this error
Webpage detalles del error
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET4.0C; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0E; .NET CLR 1.1.4322) Timestamp: Wed, 1 Feb 2012 22:24:15 UTC
Message: Object doesn't support this property or method Line: 59 Char: 4 Code: 0
What does IE not like about this? Am I doing something obviously stupid that I'm not seeing?
This is what I did originally that resulted in IE errors:
This also gives me errors in IE
I'm sorry guys. Turns out that the server was caching an older copy of the .js file and the error line I was looking at was incorrect... I apologize for wasting your time with this. The error turned out to be on a completely different line. For those who are curious it was actually failing because of this line
I've already resolved that issue though.
preguntado el 01 de febrero de 12 a las 22:02
split() creates its own array, so leave out
Tu puedes simplemente hacer
emailArray = document.getElementById('friendsEmail').value.split(",")
The constructors for primitive types are usually not recommended. You already have a string in your
friends variable, so just split y eso
emailArray = String(friends).split(','); //error here
emailArray = friends.split(','); //should work
I see no issue with your code. I think that you may have a problem with the value you are retrieving such that
friends isn't what you think it is. You can see in this jsFiddle that the general concept you're using works in IE:
var friends = document.getElementById('friendsEmail').value; var emailArray = friends.split(',');
Puedes verlo funcionar aquí: http://jsfiddle.net/jfriend00/s9S99/.
So, I think the issue is retrieving your value. That must not be what you think it is (perhaps it is null sometimes).
I strongly suspect that the actual issue is that
undefined. Are you actually trying to get the text content of the element? If so, then this works:
var friends = document.getElementById("friendsEmail"); var emailArray = friends.innerText.split(",");
Note that a simple test case on a string literal -- like
"str,str1,str2".split(",") -- would have quickly demonstrated that the
split was not the issue. It's always best to reduce things to the smallest testable unit. Otherwise, you're just guessing about the source of the error.