Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why doesn't this work in Mac IE

Status
Not open for further replies.

idratherbearobot

Programmer
Aug 24, 2004
2
US
Ok so I've got this dhtml/javascript issue, and basicly, what it boils down to is this. I have code resembling this:

<html>
<head>
<title>test file</title>
<script language="JavaScript">
<!--
var itemArray = new Array();
var item1 = "thing1";
itemArray.push(item1);
var item2 = "thing2";
itemArray.push(item2);
var item3 = "thing3";
itemArray.push(item3);
var item4 = "thing4";
itemArray.push(item4);
-->
</script>
</head>
<body>
<script language="JavaScript">
<!--
document.write(itemArray.length);
-->
</script>
</body>
</html>

On everyt browser I've tested this so far it works, the output is 4. But on Mac IE, it prints out 0. Anyone know why? Does JavaScript on a MAC version of IE not suuport the push() method?

thanks in advance
-adam
 
MSDN:


Says nothing about the push method not being supported on the Mac. However, it's a a good bet that it is not. Adding this JS to your page should remedy that:

Code:
if (![].push) Array.prototype.push = ArrayPush;
function ArrayPush() {
	this[this.length] = arguments[0];
	return(this.length);
}

You can also add pop support if you need it:

Code:
if (![].pop) Array.prototype.pop = ArrayPop;
function ArrayPop() {
	var tempItem = this[this.length-1];
	this.length--;
	return(tempItem);
}

Hope this helps,
Dan


The answers you get are only as good as the information you give!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top