【问题标题】:Cocoa webview iframe (objective c)Cocoa webview iframe(目标c)
【发布时间】:2017-02-19 08:12:01
【问题描述】:

美好的一天!

我有一个带有 iframe src.... 的 html 页面。我需要将此框架的所有 HTML 内容都获取到 NSString。

您能否建议在不将 webview 重定向到 src 的情况下最好的方法?

谢谢。

【问题讨论】:

    标签: html objective-c xcode cocoa webview


    【解决方案1】:

    您可以在NSAttributedString 中输入html 文本并从那里提取字符串。

    NSAttributedString * attrString = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUTF8StringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)} documentAttributes:nil error:nil];
    
    NSString *finalString = [attrString string];
    

    【讨论】:

    • 没有 iframe html 源代码,它是由 WebView 动态加载的。
    • webView 有一个属性 mainFrameDocument。它为您提供 DOMDocument。与 Javascript 文档相同。 developer.apple.com/reference/webkit/webview/….
    • 大型机不包含iFrame的html。
    • 据我所知,您必须将 iframe 重定向到 Web 视图,提取字符串并将两个字符串连接在一起。因为 iframe 毕竟是不同的网页。
    • 这是我想要避免的,因为 iframe 只能加载一次。这是一个跨域的iframe,这就是为什么xss保护不允许我获取html源。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多