views:

51

answers:

1

hi!

this is my first post so i am sorry for any mistakes i make :)

i know the title is confusing, but i will try to explain what i want :)

i got this website, on the website there is a schedule, this schedule change when you change different values so that it consist with the appropriate person. when you change a value a javascript function is called. is there any way for me to do this javascript (on a site i don't own) from objective-C.

so what i want is this (in a very plain description):

do javascript call "change()" on website:"My website" (i know this is not valid, but this is what i want)

also i would like to be able to change the different values and pass the function with parameters. :)

thanks

Kristian

The website is here (Norwegian):

http://www.novasoftware.se/webviewer/(S(mfq2npum0th2lxb0g5oy3045))/design1.aspx?schoolid=60810&code=545354&type=3&id=1559)

Hello i found another way to solve my problem :)

the website is automatically generating an image for each of the students. the url of an image is similar to this:

http://www.novasoftware.se/ImgGen/schedulegenerator.aspx?format=png&schoolid=60810/nb-no&type=3&id={76C567C0-161E-42C3-B054-8941DDD04F52}&period=&week=42&mode=0&printer=0&colors=32&head=0&clock=0&foot=0&day=0&width=1405&height=683&maxwidth=1405&maxheight=683

(had some problems posting the URL :/)

where you got &week=42 (you can change this to whatever you want and it works perfect). so i got it working for the mac (in safari 5)

but when i try to use this URL in the iPhone simulator i only get a white screen :(

this is the code i use:

[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.novasoftware.se/ImgGen/schedulegenerator.aspx?format=png&schoolid=60810/nb-no&type=3&id={76C567C0-161E-42C3-B054-8941DDD04F52}&period=&week=42&mode=0&printer=0&colors=32&head=0&clock=0&foot=0&day=0&width=1405&height=683&maxwidth=1405&maxheight=683"]]];

it works if i use a simpler URL like: "http://www.google.com" :S doesnt the iPhone have support for aspx?

+1  A: 

I only know this in the context of iPhone APIs...

Assuming you have the page loaded in a UIWebView inside your app...

You can call UIWebView method stringByEvaluatingJavaScriptFromString: to send javascript to the page.

If the calling function returns anything, it will be typecast as a NSString and returned to your app, but in your case it looks like you can just ignore the return value. You might need to make your Javascript look something like:

(function(){
   change();
   return "hello world";
})();

because I'm not sure how well it handles void return values.

Mike Ruhlin
Yep this is the method you want, and will execute any JS you provide it. But you do not to explicitly return a value from the Javascript at all, as it will simply return `nil` if no return ever happens in the JS.
Squeegy
Thanks for the reply...let me see if i got it right: i can do javascript on a website through objective-C, for example if i got a function named "hello" on the site i can call that function and my UIWebView will automatically update after doing the javascript. but i don't understand how i would put the "(function(){ change(); return "hello world";})();" inside a program. :/hope for some more help :)
NSString* jsToEvaluate = @"change()";NSString* ret = [webView stringByEvaluatingJavaScriptFromString:jstoEvaluate];
Mike Ruhlin
thank you very much :)