How to open web page in web view on iPhone - iphone

I want to open web page on the webView by passing the web url of that page. How is this possible?

You can load a website using this:
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://i.wrightscs.com"]]];
You can also load HTML into a UIWebView using this:
[webView loadHTMLString:#"<strong>It Work's!</strong>" baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];

Related

UIWebView back button not getting enabled

In my application I have a UIWebView in which I need to add browser like functionality(user can goBack,Forward or reload the page). To achieve this I have used the code for this tutorial.
In my code I have only one change in viewDidLoad:
I am loading data from a local html file like this:
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:#"File name" ofType:#"html" inDirectory:NO];
NSData *htmlData = [NSData dataWithContentsOfFile:htmlFile];
[self.webView loadData:htmlData MIMEType:#"text/html" textEncodingName:#"UTF-8" baseURL:[NSURL URLWithString:#""]];
instead of:
NSURL* url = [NSURL URLWithString:#"http://iosdeveloperzone.com"];
NSURLRequest* request = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];
After loading initial html file if I am making any click on that page than the back button should get enabled, instead of its getting enabled after second url click and so that I am not able to go back to the original home page.
Please help me with this.
Thanks.
I got an answer. It's because you load data into the webView without loadRequest. If you load data into webView as a string, then it won't have any url to go back or load the old page. So it won't store the data you given to the webView. For that, you need to provide the url as like this.
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"File name" ofType:#"html"] isDirectory:NO]]];

load html page on to UI web view iphone SDK 4.0

I want to load html page on to UI web view.
i'm developing using iphone sdk 4.0
Thanks
You can use this method for complex User Interface in iPhone View Controller. Because we can create ".html" page easily and use this method to display complex UI
UIWebView *webView = [[UIWebView alloc] init];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"index" ofType:#"html"]isDirectory:NO]]];
[webView setUserInteractionEnabled:YES];
[webView setScalesPageToFit:YES];
[self.view addSubview:webView];
[webView release];

display html embedded data in iphone

I'm wondering whether there's a control to display html embedded data in iphone. I need to display the information as it is on the web. The data is saved into it database together with its html tag.
So is there anyway for me to display the data accordingly..
You can use a UIWebView and load HTML using
- (void)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL
you can use a UIWebView and loadHTMLString method to load the data in HTML.
You can also change html page contents at run time using the javascript.
You can use webview for displaying displaying html embbed data.
Example is given here :
To load remote html file:
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.apple.com"]]];
To load local html file:
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"index" ofType:#"html"]isDirectory:NO]]];
To load html string:
[webView loadHTMLString:#"<img src=test.png>" baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];

Can't load JavaScript from Resource in UIWebView

I am loading a local HTML file into a UIWebView in iOS using this code
NSString *urlAddress = [[NSBundle mainBundle] pathForResource:#"index" ofType:#"html"];
NSURL *url = [NSURL fileURLWithPath:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[myWebView loadRequest:requestObj];
The page works fine, and the image linked within the HTML loads fine. However, the JavaScript linked off of the page is not loading.
The HTML, Image and JavaScript are all located in the same folder. (Resources/Html in my Project)
How can I get the JavaScript to load?
The problem was that XCode was showing me a warning:
warning: no rule to process file
'$(PROJECT_DIR)/html/orientation.js'
of type sourcecode.javascript for
architecture i386
This answer contains the solution. Basically, I had to tell XCode to not try and build the JavaScript files, and manually drag them to the "Copy Bundle Resources" directory.
The following code works for loading an html file which has javascript files in the web view
Here web is web view object and index is the html page
Web.delegate = self;
[Web loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"index" ofType:#"html"]isDirectory:NO]]];

how to load an html file locally into the uiwebview

i am having problem with how to get the uiwebview loaded with local html file .provide the cod e as well i am having the hmtl file as fp_dis-1.html.
thanks in advance
Try this,
UIWebView *page;
[page loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"your-local-file-url" ofType:#"html"]isDirectory:NO]]];