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 07-13-2011, 01:05 PM   #1 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 104
Shades of Chaos is on a distinguished road
Default stringByEvaluatingJavaScriptFromString problem

Hey all,

I am trying to use this line of code
Code:
[webView stringByEvaluatingJavaScriptFromString:@"test()"];
but it is not working. I have multiple javascript files and I do not know how to tell the program which one I am trying to use. If anyone knows how I would really appreciate it or if someone knows another way of use objective c to call javascript.

Thanks
Clinton
Shades of Chaos is offline   Reply With Quote
Old 07-14-2011, 02:15 AM   #2 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

have you loaded (and waited completition) the page that contain the javascript code?, however add a comma
Code:
[webView stringByEvaluatingJavaScriptFromString:@"test();"];
__________________
dany_dev is offline   Reply With Quote
Old 07-14-2011, 12:20 PM   #3 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 104
Shades of Chaos is on a distinguished road
Default

Yes I did wait. I put that line in
Code:
-(void)webViewDidFinishLoad{
	
	[webView stringByEvaluatingJavaScriptFromString:@"test();"];
}
and my javascript looks like
Code:
function testClint()
{
	window.location = "http://www.google.ca";
}
And it still doesn't work
Shades of Chaos is offline   Reply With Quote
Old 07-14-2011, 12:48 PM   #4 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 97
Bopols is on a distinguished road
Default

Quote:
Originally Posted by Shades of Chaos View Post
Yes I did wait. I put that line in
Code:
-(void)webViewDidFinishLoad{
	
	[webView stringByEvaluatingJavaScriptFromString:@"test();"];
}
and my javascript looks like
Code:
function testClint()
{
	window.location = "http://www.google.ca";
}
And it still doesn't work
you are calling test() but your javascript function is called testClint()
Bopols is offline   Reply With Quote
Old 07-14-2011, 12:58 PM   #5 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 104
Shades of Chaos is on a distinguished road
Default

oh sorry that was a typo. I didn't copy and paste that one into the post. In my project they are the same.
Shades of Chaos is offline   Reply With Quote
Old 07-14-2011, 06:39 PM   #6 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 104
Shades of Chaos is on a distinguished road
Default

I figured it out. I was calling the javascript before it was completely loaded. Once I put it into the webViewDidFinishLoad it started working
Shades of Chaos is offline   Reply With Quote
Old 07-15-2011, 04:05 AM   #7 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

Quote:
Originally Posted by dany_dev View Post
have you loaded (and waited completition)
__________________
dany_dev is offline   Reply With Quote
Reply

Bookmarks

Tags
call, file, javascript, string, 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: 373
9 members and 364 guests
apatsufas, chemistry, Kirkout, leostc, lzwasyc, MarkC, Sami Gh, SamorodovAlex, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,664
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Leslie80
Powered by vBadvanced CMPS v3.1.0

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