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 11-01-2011, 11:44 AM   #1 (permalink)
Registered Member
 
Join Date: Sep 2011
Location: 127.0.0.1
Posts: 51
Pyroclastic is on a distinguished road
Default UIWebView, HTML and JavaScript

I have a local HTML page stored in the bundle which I am loading up into a UIWebView just fine.
In this HTML file are links to the JavaScript files that it needs, as shown below:

Code:
<script type="text/javascript" src="../js/someJavaScriptFile.js"></script>
Now, when I load this file on my Mac it works perfectly fine since the path "../js/someJavaScript.js" file is existent from the location of the HTML file.

I have copied the js folder (which contains all the js files) into the project bundle (same level as the html file) and changed the link to the JavaScript file in the html file to:

Code:
<script type="text/javascript" src="js/someJavaScriptFile.js"></script>
However, this is still not working.

I am doing wrong something wrong?

Last edited by Pyroclastic; 11-01-2011 at 11:51 AM.
Pyroclastic is offline   Reply With Quote
Old 11-01-2011, 12:11 PM   #2 (permalink)
Registered Member
 
ebender001's Avatar
 
Join Date: Mar 2010
Location: Missouri
Age: 57
Posts: 70
ebender001 is on a distinguished road
Default

Quote:
Originally Posted by Pyroclastic View Post
I have a local HTML page stored in the bundle which I am loading up into a UIWebView just fine.
In this HTML file are links to the JavaScript files that it needs, as shown below:

Code:
<script type="text/javascript" src="../js/someJavaScriptFile.js"></script>
Now, when I load this file on my Mac it works perfectly fine since the path "../js/someJavaScript.js" file is existent from the location of the HTML file.

I have copied the js folder (which contains all the js files) into the project bundle (same level as the html file) and changed the link to the JavaScript file in the html file to:

Code:
<script type="text/javascript" src="js/someJavaScriptFile.js"></script>
However, this is still not working.

I am doing wrong something wrong?
Use the NSBundle:
NSString *path = [[NSBundle MainBundle] bundlePath;
NSURL *baseURL = [NSURL fileURLWithPathath];

Load your html as an HTMLString:
[yourWebView loadHTMLString:theHtmlString baseURL:baseURL];

In your HTML file, refer to your js file as src="someJavaScriptFile.js", and not by some sort of file hierarchy used on a Mac OSX.

Ed
ebender001 is offline   Reply With Quote
Old 11-01-2011, 12:43 PM   #3 (permalink)
Registered Member
 
Join Date: Sep 2011
Location: 127.0.0.1
Posts: 51
Pyroclastic is on a distinguished road
Default

Thanks for your quick reply Ed, however, this still doesn't work. This is my code as follows:

Code:
NSString *myFilePath = [[NSBundle mainBundle] pathForResource:@"myFile" ofType:@"htm"];
   
NSString *htm = [NSString stringWithContentsOfFile:myFilePath encoding:NSUTF8StringEncoding error:nil];
    
NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
    
[myWebView loadHTMLString:htm baseURL:baseURL];
And the hmtl page references the js file as follows:

Code:
<script type="text/javascript" src="someJavaScriptFile.js"></script>
Any ideas?
Pyroclastic is offline   Reply With Quote
Old 11-01-2011, 01:29 PM   #4 (permalink)
Registered Member
 
ebender001's Avatar
 
Join Date: Mar 2010
Location: Missouri
Age: 57
Posts: 70
ebender001 is on a distinguished road
Default

Quote:
Originally Posted by Pyroclastic View Post
Thanks for your quick reply Ed, however, this still doesn't work. This is my code as follows:

Code:
NSString *myFilePath = [[NSBundle mainBundle] pathForResource:@"myFile" ofType:@"htm"];
   
NSString *htm = [NSString stringWithContentsOfFile:myFilePath encoding:NSUTF8StringEncoding error:nil];
    
NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
    
[myWebView loadHTMLString:htm baseURL:baseURL];
And the hmtl page references the js file as follows:

Code:
<script type="text/javascript" src="someJavaScriptFile.js"></script>
Any ideas?
Sorry its not working.
Maybe it has to do with how your javascript file is being handled (a guess). Perhaps this StackOverflow post is germane to your query:
How to add javascript file to Xcode4 - Stack Overflow
ebender001 is offline   Reply With Quote
Old 11-01-2011, 02:36 PM   #5 (permalink)
Registered Member
 
Join Date: Sep 2011
Location: 127.0.0.1
Posts: 51
Pyroclastic is on a distinguished road
Default

Quote:
Originally Posted by ebender001 View Post
Sorry its not working.
Maybe it has to do with how your javascript file is being handled (a guess). Perhaps this StackOverflow post is germane to your query:
How to add javascript file to Xcode4 - Stack Overflow
Thanks alot! That did the trick ....

Note to self, stop asking questions during a 19hour day haha

Thanks again
Pyroclastic is offline   Reply With Quote
Reply

Bookmarks

Tags
html, javascript, loading html, 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: 400
11 members and 389 guests
7twenty7, buggen, EvilElf, j.b.rajesh@gmail.com, LunarMoon, morterbaher, QuantumDoja, sacha1996, Sami Gh, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,673
Threads: 94,122
Posts: 402,906
Top Poster: BrianSlick (7,990)
Welcome to our newest member, morterbaher
Powered by vBadvanced CMPS v3.1.0

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