0

I want to load a specific part of a webpage on a UIWebView

 [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://jlhs.schoolloop.com/mobile/login"]]];
    [_webView loadHTMLString:@"<html><body><div class="slideshow_outer"></div></body></html>" baseURL:nil];
    [_webView setNeedsDisplay];

The first is the website address The second is the part of the HTML I want to load and the third is to display it.

I get an error on the HTML string I put. How do I fix this or is there a better way of writing it? It won't work, how do I go on with this?

Cyril
  • 2,783
  • 1
  • 24
  • 35
  • 1
    Use simple quotes ' for the html or escape the double quote with \" – jcesarmobile May 07 '15 at 16:47
  • possible duplicate of [How to get double quotes into a string literal?](http://stackoverflow.com/questions/12338818/how-to-get-double-quotes-into-a-string-literal) – Guillaume Algis May 07 '15 at 16:49
  • @jcesarmobile okay that worked i was able to run but it would not load. – Cyril May 07 '15 at 16:50
  • 1
    @CyrilIvarGarcia - "that worked i was able to run but it would not load" - Your first line of code seems to fill the web view from a URL, your second line discards that and replaces it with the HTML you provide, this seems curious. What do you mean by "The second is the part of the HTML I want to load"? If you can explain (by editing the question or starting a new one) better what your problem is, past the syntax error with the quotes, then someone might be able to help you. – CRD May 07 '15 at 18:18
  • Your question makes no sense, as @CRD told you, you load a website first and then you load the html string that replaces the web page – jcesarmobile May 07 '15 at 20:49

1 Answers1

0
 // show HTML content in webview there is two different types, as follow
    // 1. Using URL
    // for show web view with online url
    [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://jlhs.schoolloop.com/mobile/login"]]];

    // 2. Using string
    // for show web view with help of string, local page
    NSString * htmlPage = @"<html><head><meta http-equiv=\"Content-type\" content=\"text/html charset=UTF-8\" /><meta name=\"viewport\" content=\"width=device-width; initial-scale=1.0; maximum-scale=1.5; user-scalable=0;\"/></head><body style=\"font-size:13px;font-family:Arial;-webkit-user-select:none;\">Write here your HTML content </body></html>";

    [_webView loadHTMLString:htmlPage baseURL:nil];
    // you can't use it at a time, as per your requirement use one of these.

    I hope you undersand want I want to explain.
Pravin Tate
  • 1,145
  • 8
  • 18