Click to See Complete Forum and Search --> : JS1.2 and IE5.0
EmKaa
06-16-2003, 03:54 PM
I am using the push() method to add an entry in my array.
This works fine with IE6.0, but fails in IE5.0 stating that it is not a valid method for the object.
The push() method was added with JS1.2 and IE5.0 claims to support JS1.2...
What is going wrong ?
Is there an easy alternative to add entries in an array ?
Perhaps there is something else wrong with your code. It should work fine in IE5. Please post your code.
You can also just add to an array by setting an extra (empty) value in the array and just setting that value instead of using the push() method; however, if you loop through the array at any time you will need to subtract one from it to prevent looping through an empty array value.
Jona
Charles
06-16-2003, 05:02 PM
It's easy enough to test to see if Array.push() exists and to define you own version if it does not.
<script type="text/javascript">
<!--
if (!Array.prototype.push) Array.prototype.push = function (e) {this[this.length] = e}
var foo = ['fee', 'fie', 'foe'];
foo.myPush('fum');
alert (foo);
// -->
</script>
Charles, how can myPush() be a method when it is not named? (You have only defined it as push() not myPush()).
Jona
Charles
06-16-2003, 05:24 PM
Oops, that got in there as a part of my making sure that it actually works before posting. Thanks for catching that.
<script type="text/javascript">
<!--
if (!Array.prototype.push) Array.prototype.push = function (e) {this[this.length] = e}
var foo = ['fee', 'fie', 'foe'];
foo.push('fum');
alert (foo);
// -->
</script>
EmKaa
06-16-2003, 05:30 PM
My code can be found on http://users.belgacom.net/ketels/marc/blink.htm.
OK, that's neat. Glad you got it working. :cool:
Jona
EmKaa
06-17-2003, 05:06 PM
Well, the script is still NOT running with IE5.0...
Charles
06-17-2003, 06:16 PM
Did you prepend if (!Array.prototype.push) Array.prototype.push = function (e) {this[this.length] = e} to your scripts?
EmKaa
06-18-2003, 04:39 PM
Sorry I did forget to mention it :
yes, when I add your instruction on top of my script, it works, also in IE5.0. Many thanks, Charles.
But my question remains unanswered :
What is the reason that JS1.2 is not properly handled by IE5.0 ?
There may be lots of other JS1.2 methods and features that are not recognized by IE5.0 ...
Originally posted by EmKaa
What is the reason that JS1.2 is not properly handled by IE5.0 ?
There are many possible reasons. IE5.0 should handle all JS1.2 appropriately. So I'm not sure what could be wrong...
Jona