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 05-09-2009, 02:44 PM   #1 (permalink)
Registered Member
 
Join Date: Sep 2008
Posts: 169
Danneman is on a distinguished road
Default Another problem with stringByEvaluatingJavaScriptFromString

Ive got a js-function in a webview that focuses on a select-list and selects it, which works fine.

Code:
function selectLetter()
{
document.getElementById("select_letter").focus();
document.getElementById("select_letter").select();
}
However, when invoking the same functionality from obj-c code using stringByEvaluatingJavaScriptFromString, it wont execute. Nothing happens.

Code:
[self.webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.getElementById('select_letter').focus();"]];
[self.webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.getElementById('select_letter').select();"]];
Ive tried other types of code with stringByEvaluatingJavaScriptFromString manipulating just that select-list, which has worked fine. For instance:

Code:
[self.webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.getElementById('select_letter').style.visibility='hidden';"]];
Any suggestions?
Danneman is offline   Reply With Quote
Old 06-23-2009, 12:02 PM   #2 (permalink)
New Member
 
Join Date: Apr 2008
Location: Berlin
Posts: 13
geppi24 is an unknown quantity at this point
Default

Hey,
I ran into the same problem. What I figuered out so far, it doesn't help either to call the JS-function which should does the job via the stringByEvaluatingJavaScriptFromString:-method.

Any help is highly apriciated!
geppi24 is offline   Reply With Quote
Old 06-25-2009, 12:16 PM   #3 (permalink)
Registered Member
 
Join Date: Sep 2008
Posts: 169
Danneman is on a distinguished road
Default

Unfortunately, I didnt find any solution to this and had to abandon the idea completely :/
Danneman is offline   Reply With Quote
Old 06-25-2009, 04:10 PM   #4 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

Are you waiting until after the content has loaded before you call this function? Otherwise you'll get nothing, of course.

You could also try logging the intermediate steps, see where you're getting stuck.

Code:
NSString *result;

result = [self.webView stringByEvaluatingJavaScriptFromString: @"document"];
NSLog (@"%@", result); //should log the document object?

result = [self.webView stringByEvaluatingJavaScriptFromString: @"document.getElementById"];
NSLog (@"%@", result); //should log a function

result = [self.webView stringByEvaluatingJavaScriptFromString: @"document.getElementById('select_letter')"];
NSLog (@"%@", result); //should log the node
__________________

Free Games!
smasher is offline   Reply With Quote
Old 01-24-2012, 05:08 AM   #5 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 316
iphonegamedeveloper is on a distinguished road
Send a message via Yahoo to iphonegamedeveloper
Default

Quote:
Originally Posted by smasher View Post
Are you waiting until after the content has loaded before you call this function? Otherwise you'll get nothing, of course.

You could also try logging the intermediate steps, see where you're getting stuck.

Code:
NSString *result;

result = [self.webView stringByEvaluatingJavaScriptFromString: @"document"];
NSLog (@"%@", result); //should log the document object?

result = [self.webView stringByEvaluatingJavaScriptFromString: @"document.getElementById"];
NSLog (@"%@", result); //should log a function



result = [self.webView stringByEvaluatingJavaScriptFromString: @"document.getElementById('select_letter')"];
NSLog (@"%@", result); //should log the node






How to validate whether the element is present or not. For me in both cases result is same.Its not printing any values in log. I need to check whether the particular id is present or not.Please help
iphonegamedeveloper is offline   Reply With Quote
Old 01-24-2012, 06:03 AM   #6 (permalink)
Registered Member
 
apatsufas's Avatar
 
Join Date: Jan 2011
Location: Thessaloniki, Greece
Posts: 121
apatsufas is on a distinguished road
Default

If NSLog doesn't print anything to the log it means that the NSString you are trying to print is empty.
__________________
SQLed - Your Database Manager on the go

iAZConverter - Converts everything from A to Z
apatsufas is offline   Reply With Quote
Reply

Bookmarks

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: 317
6 members and 311 guests
givensur, guusleijsten, jbro, mer10, n00b, yomo710
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,113
Posts: 402,880
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

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