I am trying to write an application to show a web page in a web view for this link:
http://just4u.safeway.com
But the page can not be shown in the UiWebView, I got a message:
This page contains the following
errors: error on line 90 at column 11:
AttValue: " or ' expected.
Can someone let me know what could be the problem? I already added code to handle redirect, but still get the same problem.
Thanks
Try explicitly setting the MIME type of the page to be "text/html". Otherwise it may be parsed in the UIWebview as xhtml. Also check that your <!DOCTYPE> is not claiming to be xhtml.
I was running into a very similar problem.
I was using the loadRequest method of UIWebView, which was causing the UIWebView to interpret it as XHTML.
I instead used NSURLConnection to asynchronously load the data for the webpage, then used
[webView loadData:downloadedData MIMEType:#"text/html" textEncodingName:#"UTF-8" baseURL:[NSURL URLWithString:pageURLString]];
and got the page to display without the pink error box at the top.
This is essentially the same solution as PengOne suggests - I just wanted to confirm that the suggestion works fine, and show the sample code that worked for me.
Related
I am trying to load a http URL in WKWebView, the page loads perfectly fine on enabling NSAllowsArbitraryLoads and NSAllowsArbitraryLoadsInWebContent in info.plist file. But during navigating the Application, html pages are not loaded completely and my custom spinner doesn't disappear.
I have tried to NSExceptionDomains but no luck.
Everything works fine when I tried to load url with https://myurl
Please suggest
I found answer to my above question
history.back() was not working on HTML back button in iOS 11. Adding history.go(-1) worked for me.
I am opening many urls from my application and they are working fine. All these urls I am opening in UIWebView in a custom ViewController.
But recently I found an issue that when I am passing a url which contains a PDF, it opens fine , but when I copy something from that PDF by long pressing on the PDF from UIWebView, and then when I try to go back from that ViewController, the app crashes giving me error like:
[UIPDFPageView nextResponder]: message sent to deallocated instance
Without copying any thing I can normally go back and continue with my app. I tried a lot but could not figure out the problem.
If any one can help, It will be honor.
Thanks in advance... !!!
I guess you might be calling the below line when going back from your UIWebView's ViewController :
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"about:blank"]]];
May be to clear out your WebView before leaving. There are better and easy ways to so this like given here:
Hope this helps...
All the best!!!
I have an app that uses a Table View to show a list of stories a user can read and when they tap on a particular title a Detail View will open up and the story is displayed.
To begin with I had the app loading up the stories directly from the web and this worked perfectly. I used an array and to pass the details of the particular stories web address and used the following to load up the page
[detailWebView loadRequest:[NSURLRequest requestWithURL:detailURL]];
Now I want to load up files locally instead and from searching around I found the following
[detailWebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:detailURL ofType:#"html"]isDirectory:NO]]];
and it does load up my local 'Story 1' HTML file but that same HTML file gets loaded up regardless of the file name being passed by detailURL in my Table View which takes the format of
[bookOne addObject:[[NSMutableDictionary alloc]
initWithObjectsAndKeys:#"Story One Title",#"name",
#"Story 1",#"url",nil]];
If I pass it a file name that doesn't exit the program quits so I'm pretty sure the different file names are being passed but the same HTML page always shows.
I've tried reboots etc but the same file always opens up, your help would be really appreciated.
Thanks
Kieron
Try to load the files with
loadHTMLString:baseURL:
it might be that NSURLRequest caches the file/response.
A different solution would to create an instance of the NSURLRequest with initWithURL:cachePolicy:timeoutInterval: and pass NSURLRequestReloadIgnoringLocalAndRemoteCacheData for the cachepolicy
Thanks Nick, while loadHTMLString didn't provide the answer it got me thinking differently and on the right track as to the real cause of the problem.
When using a web address in the first example detailURL had been set as NSURL and when I changed it to NSString my code worked fine. I don't understand why it would cause the loading of the HTML file(s) to act so weirdly but everything is running fine now, the different stories all load up as there should and there are no caching issues of any sort.
In my iPhone application I'm parsing RSS feed to get html and keep it. Afterwards I display this html in UIWebView. The problem is that html contains urls of images, if there is network connection everything is ok, UIWebView loads and displays these images, but if there is no connection it shows text but in place of images shows frame with blue square inside
How can I get rid of it?
Thank you
Check programmatically to make sure that you have an internet connection.
See this question and its accepted answer on how to do that.
If you don't have an internet connection, then you have a couple of options. You can either:
Parse through your html, replace the <img> tags with blanks (this will completely get rid of the images and their associated blue question mark boxes.
Parse through your html, replace the src part of <img src="somewebsite"> with a reference to an image placeholder in the project bundle.
XPath is your friend when it comes to parsing html. Although if you wanted to, you could do all of this with NSSTring.
I am currently opening a webpage in UIWebView and submitting a form which performs a query on the server side and youtube video is returned (if available). I have no say/control over the server side implementation.
This webview works fine on iPhone/iPod, however, when I try to run the same app on iPad there is no response after submitting the form.
I created a dummy app, compiled on iOS 3.2 and problem is still there.
I put NSLogs in webview delegate methods which shows that after the form is submitted (UIWebViewNavigationTypeFormSubmitted) nothing happens.
I'm unable to figure out why this happens only on iPad and not on iPhone/iPod Touch.
I have created the webview in IB and setting the URL is viewDidLoad
[viewTourWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.realestatetour.com/mobiletours.htm"]]];
The URL for reference is http://www.realestatetour.com/mobiletours.htm
Enter the Tour ID as 10.
Thanks
The reason it wasn't working is because the form opens the result in a new page, (i.e. _blank) and apparantly all links opening in new window are ignored by uiwebview and its delegates.
I found 2 possible solutions for this:
1) Modifying the html using javascript to replace all _blank with _self for all anchor tags.
(source)
2) A more elegant solution which works for handling links which open a new window.
(source)
In my case i recreated the web page displaying form on the iphone app and changed _blank to _self.