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 09-11-2010, 03:01 PM   #1 (permalink)
14 Year Old iOS Developer
 
H4CK3R's Avatar
 
Join Date: Jun 2010
Age: 16
Posts: 73
H4CK3R is on a distinguished road
Default Get Text From UIwebView With Javascript

Code:
<div id="count">
1
<span style="font-size: 15px; ">
<span>
<br id="miobr"/>
<br id="miobr"/>
</span>
</span>
</div>

I need to get the 1 from the html snippet loaded into a webview but the javascript i've tried doesn't seem to work?

Code:
NSString *pms = [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsById('count').innerHTML"];


NSString *pms = [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsById('count').innerText"];

//This last one is changing the documents title to it (or trying to) as i know i can extract the title quite easily.

[webView stringByEvaluatingJavaScriptFromString:@"var script = document.createElement('script');"
	 "script.type = 'text/javascript';"
	 "script.text = \"function myFunction() { "
	 "var field = document.getElementById('count');"
	 "document.title = field.InnerText;"
	 "}\";"
	 "document.getElementsByTagName('head')[0].appendChild(script);"];

	[webView stringByEvaluatingJavaScriptFromString:@"myFunction();"];

	NSString *pms = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];

Any help with this?

I'm not that good with javascript so that might be my problem but i don't know what would work?
H4CK3R is offline   Reply With Quote
Old 09-12-2010, 03:33 AM   #2 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 7
mainlime is on a distinguished road
Default

You have a typo in your first two lines. getElementsById should be getElementById (no 's')
mainlime is offline   Reply With Quote
Old 09-12-2010, 06:30 AM   #3 (permalink)
14 Year Old iOS Developer
 
H4CK3R's Avatar
 
Join Date: Jun 2010
Age: 16
Posts: 73
H4CK3R is on a distinguished road
Default

Thank you it worked!!
H4CK3R 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: 344
11 members and 333 guests
bignoggins, carlandrews, cgokey, givensur, hzwegjxg, jenniead38, linkmx, mraalex, PixelInteractive, Trickphotostudios
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

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