【问题标题】:How to show a section of HTML using webview?如何使用 webview 显示 HTML 的一部分?
【发布时间】:2014-02-01 02:19:39
【问题描述】:

我一直在寻找问题试图找到答案,但我似乎无法弄清楚我在做什么。我想在 webview 中显示我的 HTML 的一部分。

UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 640.0)];
NSURL *URL = [NSURL URLWithString:@"http://stackoverflow.com"];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:URL];
webView.delegate = self ;
[webView loadRequest:requestObj]; 
[self.view addSubview:webView];

这可以完美地显示整个网页。但是假设我只想显示某个 div,我该怎么办?

我尝试添加 getElemntByID 和 getElementsByClass 但它似乎对我不起作用..

【问题讨论】:

    标签: html iphone xcode webview uiwebview


    【解决方案1】:

    你的问题的答案。

       NSString *htmlPage = @"<html><body><h1>StackOverFlow</h1></body></html>";
        [yourWebView loadHTMLString:htmlPage baseURL:nil];
    

    【讨论】:

    • 当我输入我的 HTML 时,我收到了使用未声明标识符的错误。它是我试图展示的网站上的一个小部件。
    • 哪一个是未声明的
    • 期待;在 HTML 中的 id 处。 'iframe id="twitter-widget-0' 你看我想显示这个 iframe。
    • 这就是我所拥有的:@"&lt;head&gt;&lt;div class="container"&gt;&lt;div class="row"&gt;&lt;section class="span12" role="main"&gt;&lt;div class="row"&gt;&lt;div class="span3"&gt;&lt;a class="timeline" data-dnt="true"&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/section&gt;&lt;/div&gt;&lt;/script&gt;&lt;/body&gt;&lt;/html&gt;";
    猜你喜欢
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多