Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-16-2012, 03:48 PM   #1 (permalink)
learner2011
 
Join Date: Mar 2011
Posts: 115
ashwinr87 is on a distinguished road
Default Calling Javascript using UIWebView

I am trying to call a javascript in a html page using the function -

Code:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writablePath = [documentsDirectory stringByAppendingPathComponent:@"BasicGraph.html"];
NSURL *urlStr = [NSURL fileURLWithPath:writablePath];

NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *myPathInfo = [[NSBundle mainBundle] pathForResource:@"BasicGraph" ofType:@"html"];
[fileManager copyItemAtPath:myPathInfo toPath:writablePath error:NULL];

[graphView loadRequest:[NSURLRequest requestWithURL:urlStr]];
[graphView stringByEvaluatingJavaScriptFromString:@"methodName()"];
Here is the javascript on the html page -

Code:
<script>
function methodName()
    {
        alert(hi);
    } 
window.onload = function ()
    {
      // Code Omitted
    }
</script>
However, the function methodName() is not getting called but after window.onload = function () everything is working fine..

I am trying to integrate RGraphs into my application and Basic.html is the html page in which the javascripts are written.

It would be great if someone could help me out with this.
ashwinr87 is offline   Reply With Quote
Old 01-16-2012, 05:09 PM   #2 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Jan 2010
Location: Issaquah, WA
Age: 42
Posts: 1,244
dljeffery is on a distinguished road
Default

The only obvious issue I see is that you are not waiting for your HTML to finish loading.

You should implement the UIWebViewDelegate method webViewDidFinishLoad and make your javascript call from there.
__________________
Recall It! Tag your notes. Tag your photos. Tag your thoughts. Tag your life.

Recall It! for iPad

http://www.dljeffery.com
dljeffery is offline   Reply With Quote
Old 01-17-2012, 08:24 AM   #3 (permalink)
learner2011
 
Join Date: Mar 2011
Posts: 115
ashwinr87 is on a distinguished road
Default

yes.. that was the problem .. I figured it out in a bit.. Also I had to set the delegate to self..
Thanks for the help..

Quote:
Originally Posted by dljeffery View Post
The only obvious issue I see is that you are not waiting for your HTML to finish loading.

You should implement the UIWebViewDelegate method webViewDidFinishLoad and make your javascript call from there.
ashwinr87 is offline   Reply With Quote
Reply

Bookmarks

Tags
ios5, javascript, rgraphs, uiwebview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 393
10 members and 383 guests
7twenty7, Atatator, glenn_sayers, guusleijsten, iphonedevshani, QuantumDoja, sacha1996, Sami Gh, tim0504, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,674
Threads: 94,122
Posts: 402,907
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Atatator
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:42 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0