473,385 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Works in Firefox but not in IE6, any help appreciated....

Hi,

Thanks alot in advance. I got the following two functions in my
javascript which work fine in Firefox 1.5 but not in IE6. Can someone
please help? Thank you again.

--------------------snip---------------------
function myClass(){
var self = this;
}

function defaultAction(){
myClass.prototype.callOut = eval("function (){ " +
"alert('testing myClass'); " +
"}");
myObject = new myClass();
if( typeof(myObject) == 'undefined' ){
alert("myObject is not defined");
}
else if( typeof(myObject) == 'function' ){
alert("myObject is a function");
}
else{
alert("myObject is " + typeof(myObject));
}
for (property in myObject) {
alert("myObject has property - " + property);
}
myObject.callOut(); // Problem appear here. IE complains Object
Expected
}

Dec 28 '05 #1
4 3418
DamonChong wrote:
Hi,

Thanks alot in advance. I got the following two functions in my
javascript which work fine in Firefox 1.5 but not in IE6. Can someone
please help? Thank you again.

A couple of tips when posting code: do not use tabs, use 2 or 4 spaces
for indentation and manually wrap code at about 70 characters to
prevent auto-wrapping. Also, reduce your test case to the minimum
required (though here that isn't much of an issue).

--------------------snip---------------------
function myClass(){
var self = this;
}

function defaultAction(){
myClass.prototype.callOut = eval("function (){ " +
"alert('testing myClass'); " +

Eval is almost never required:

myClass.prototype.callOut = function (){
alert('testing myClass');
}

"}"); myObject = new myClass();
if( typeof(myObject) == 'undefined' ){
alert("myObject is not defined");
}
else if( typeof(myObject) == 'function' ){
alert("myObject is a function");
}
else{
alert("myObject is " + typeof(myObject));
}
for (property in myObject) {
alert("myObject has property - " + property);
}
myObject.callOut(); // Problem appear here. IE complains Object
Expected
}


The following works fine in Firefox and IE 5.2:

function myClass(){
var self = this;
}
function defaultAction(){
myClass.prototype.callOut = function (){
alert('testing myClass');
}

myObject = new myClass();

alert("myObject is " + (typeof myObject) );

for (property in myObject) {
alert("myObject has property - " + property);
}

myObject.callOut();

}

defaultAction();

--
Rob
Dec 28 '05 #2
Thanks alot Rob. The problem is I need the eval() method as I don't
know what is the functions that might be created dynamically during
runtime. In this case, I simply coded the eval("function().....") but
in future it could be like below,

myClass.prototype.callOut = eval(strval); // where strval is a String
variable

I guess it is abit convulated but surprising it works fine in Firefox.
Is this way of dynamically creating a function supported in IE 5 and
above?

Thank you again.

Dec 28 '05 #3
Damon Chong wrote:
Thanks alot Rob. The problem is I need the eval() method as I don't
know what is the functions that might be created dynamically during
runtime. In this case, I simply coded the eval("function().....") but
in future it could be like below,

myClass.prototype.callOut = eval(strval); // where strval is a String
variable

I guess it is abit convulated but surprising it works fine in Firefox.
Is this way of dynamically creating a function supported in IE 5 and
above?
I can't comment on that in general, I'm testing on Mac OS at the
moment so IE 5.2 is all I can do.

What you are trying to do does not appear to be much different from
using JSON, here is another alternative (tested in Safari, Firefox &
IE 5.2):

<script type="text/javascript">

var myObject;
var funcBody = "alert('testing myClass')"

function myClass(){
var self = this;
}

function defaultAction()
{
myClass.prototype.callOut = new Function(funcBody);

myObject = new myClass();

for (property in myObject) {
alert("myObject has property - " + property);
}
myObject.callOut();
}

defaultAction();

</script>
There is a (rather long) discussion on eval and JSON here, but Jim
Ley's resonponse seems pretty good:

<URL:
http://groups.google.com/group/comp....70fb75d49557a7


--
Rob
Dec 28 '05 #4
Thanks alot Rob, I tried it out on IE6 and it is working now. Your tips
were very helpful in solving my problem. Thanks again! =D

Dec 29 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Fabri | last post by:
I would like to ask you the following: I use Macromedia Dreamweaver as an editor for HTML and Js. It also writes some js functions to simply validate forms. I always used it with no bugs. ...
4
by: goga | last post by:
Hi there, The following simple validation code works in internet explorer but doesn't in firefox. Specifically, in firefox shows the alert message and then loads the action page anyway. Any...
1
by: dasayu | last post by:
Hi, I have a custom object called gridWidget. I am consistantly getting an error in FireFox when I click on an href, which calls a function defined on the object. The generated link looks similar...
2
by: ranger7419 | last post by:
I'm trying to figure out why this script will work in IE 6 but not Firefox, and so I need someone here with a far better grasp on javascript to explain this. Basically, I have a page with several...
9
by: Dave | last post by:
Hi, I've been trawling the web for answer to my problem with no luck although I'm hardly alone it seems! Below is the generated source for an ASP page that posts a value called 'album' to...
4
by: DavidJColbran | last post by:
Hello - new to the board and wondering if anyone can help with this. I have a site developed with the CMS ModX. It has a CSS UL list menu on the left hand side that needs to have roll-overs and a...
3
by: hardcorey | last post by:
i basically have a couple songs that ive made on my site, and im using an onClick event to play each song. basically the onClick event calls the javascript function. heres my javascript: ...
5
by: dmk | last post by:
Hi All, function getWindowSize() { var myWidth = 0, myHeight = 0; if( typeof( window.innerWidth ) == 'number' ) { //Non-IE myWidth = window.innerWidth; myHeight =...
7
by: mike57 | last post by:
The minimal AJAX script below works in Firefox, but not in IE, Opera, or Chrome. I could use some suggestions or referrals to resources that will help me get the script working in other browsers. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.