473,323 Members | 1,550 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,323 software developers and data experts.

eval workaround in Safari

Hello ppl,

I am new to working with the Safari browser supported in Mac OS, I am trying to perform eval of a Javascript(string) which is working in IE / Firefox but not working in Safari. I am basically trying to create an instance of an object with eval.

For ex:
eval( "var x = new ImageLoader( );" ) ;

any leads or suggestions on this issue would be great.
Nov 27 '07 #1
9 5878
gits
5,390 Expert Mod 4TB
hi ...

could you tell why you use eval for that? may be we don't have to workaround a browser-specific thing ... but the use of eval at all :)

kind regards
Nov 27 '07 #2
hey,

i dont know wat object i am going to make of before hand. I mean i get the Object name from a variable, then concatenate the new operator and braces with it.

something like this

"var x = new " + className + "();"

this className will vary...that is why i want to use eval here. But safari doesnt seem to support eval. Any ideas ???

Thanks
Nov 27 '07 #3
gits
5,390 Expert Mod 4TB
i see ... hmmm ... i didn't know that eval-issue with safari so i'll try it this evening ... but you could use the following code at first and give it a try:

Expand|Select|Wrap|Line Numbers
  1. function create_class(class) {
  2.     return new Function('return new ' + class)();
  3. };
  4.  
  5. var x = create_class(class_name);
kind regards
Nov 27 '07 #4
ok will try this...you just try that out in safari and let me know...
Nov 27 '07 #5
gits
5,390 Expert Mod 4TB
hi ...

i tested the following in my safari 3 - addressbar:

Expand|Select|Wrap|Line Numbers
  1. javascript:eval( "var x = new Array;" ) ; alert(x instanceof Array);
the alert said 'true' :) so it works ... as i expected ... so could you tell what particular error you get when using your eval with safari? (i simply used Array instead of an ImageLoader-class ... for testing purposes)

kind regards
Nov 27 '07 #6
hey

eval seems to be working...my problem is that i have 5 classes that could be instantiated and i dunno which one i will have to instantiate....that is why i am using eval to instiate the classes...is there any difference between IE / Firefox and Safari in how they evaluate the script...scope or something could be an issue ???
Nov 28 '07 #7
gits
5,390 Expert Mod 4TB
hey

eval seems to be working...my problem is that i have 5 classes that could be instantiated and i dunno which one i will have to instantiate....that is why i am using eval to instiate the classes...is there any difference between IE / Firefox and Safari in how they evaluate the script...scope or something could be an issue ???
there shouldn't be differences between safari and FF as far as i know ... all ajax-json-evals i know work the same ... so in case the className you pass to it and the class itself is ok and available to javascript at runtime it should work ... again: what error do you get in safari?

kind regards
Nov 28 '07 #8
Hey,

I am sorry eval s working in Safari...I tried out a few examples....the issue here has turned out in a different manner...I load javascripts dynamically which contains the classes...now the isue is that there is no onload / on readystatechange that is fired when a tag is loaded and ready...that i why my classes were undefined because i initialize before these scripts in these tags get loaded...so am trying to find some way of doing that now...any clues on that?
Nov 29 '07 #9
gits
5,390 Expert Mod 4TB
hmmm ... please give an example code for that problem ... you have to ensure that the classes are ready to use before you want to create an instance of one of them ... but i don't have a clue on how you actually have it done ... so it would be better to see it or have a detailed description step by step regarding your current code ...

kind regards
Nov 29 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: lawrence | last post by:
I have a string which I want to send to eval(). How can I test it ahead of time to make sure it is valid code? I don't want to send it to eval and get parse errors. I want to do something like...
6
by: Paddy | last post by:
Hi, I got tripped up on the way eval works with respect to modules and so wrote a test. It seems that a function carries around knowledge of the globals() present when it was defined. (The...
12
by: Scott Mitchell | last post by:
I am using the onbeforeunload client-side event to prompt a user when leaving a page after they have made changes, as discussed in this article: Using ASP.NET to Prompt a User to Save When Leaving...
3
by: Jeremy Sanders | last post by:
Hi - I'm trying to subclass a dict which is used as the globals environment of an eval expression. For instance: class Foo(dict): def __init__(self): self.update(globals()) self = 42
4
by: Angel | last post by:
Hello Everybody, I have the following lines in my code 1) totalElements=eval("document."+formname+".RCBillingCycle"+totalRCRows+".length") 2) var newoption=new Option...
4
by: niko.nyman | last post by:
I noticed weird results when using eval() to do some simple calculations. Here are a few eval() statements and the corresponding results from JavaScript: eval("1.2+0.97") =2.17 eval("1.2+0.98")...
7
by: petermichaux | last post by:
Hi, I have tried the following based on suggestions of the best way to insert JavaScript into a page. This is instead of using eval(). Unfortunately IE says "unexpected call to property or...
12
by: Logos | last post by:
Yes, eval is a tool of the devil and I'll burn for using it. However, in this instance it's quite handy and I'm quite lazy. So, here's a weird one, and I'm wondering if anyone has a workaround....
6
by: =?ISO-8859-1?Q?Ignacio_Burgue=F1o?= | last post by:
Hi everyone. I'm dealing with some javascript code which uses eval to access properties of an object. For instance, I have the following: var events = {}; events.flatUsers = {};...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.