是否可以读取已加载到的网页的原始HTML内容UIWebView?
如果没有,是否有另一种方法从iPhone SDK中的网页(例如.NET的等价物WebClient::openRead)中提取原始HTML内容?
我有一个非常简单的iOS应用程序,带有uiwebview加载一个非常简单的测试页面(test.html):
<html>
<body>
<img src="img/myimage.png" />
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我将此test.html文件加载到我的Web视图中:
NSURL *url = [[NSBundle mainBundle] URLForResource:@"test" withExtension:@"html"];
NSString *html = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
NSURL *baseUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
[webView loadHTMLString:html baseURL:baseUrl];
Run Code Online (Sandbox Code Playgroud)
如果我在没有相对路径的情况下引用图像并将引用的图像放在根目录下的根目录下 - >在XCode中复制捆绑资源,这可以正常工作,但是我无法使用我的html文件中显示的相对路径.必须有一种方法可以做到这一点,我有很多图像,CSS,javascript文件,我想加载到webview中,我希望不必拥有根目录中的所有内容,并且必须更改我的网站中的所有引用应用程序.
我使用WKWebView登录网站,现在我想解析网站的HTML.如何在swift中访问网站html?我知道它如何用于UIWebView但不适用于WKWebView.
谢谢你的帮助!
我试图在WkWebView中显示我之前下载并存储在String中的html页面.
这就是我设置WkWebView的方法:
webView = WKWebView(frame: self.blankView.frame)
webView.navigationDelegate = self
webView.loadHTMLString(tipShow.htmlString!, baseURL: nil)
view.addSubview(webView)
Run Code Online (Sandbox Code Playgroud)
我想要显示的html字符串是:
<html> <style type="text/css"> * { -webkit-touch-callout: none; -webkit-user-select: none; /*
Disable selection/copy in UIWebView */
}
</style> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,
initial-scale=1">
<title>TITLE</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css">
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> <script
src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script> </head>
<body>
<div data-role="page" id="page1">
<div align=justify style="margin-left:20px; margin-right:20px">
<font size="4.5" face="HelveticaNeue-Light"><br>
<p>
THIS IS A TEST
</p>
</div> </div>
</body></html>
Run Code Online (Sandbox Code Playgroud)
当WkWebView在我的视图中显示时,它就像这样永远.
有人可以解释一下为什么以及如何解决这个问题?
我UIWebview使用loadHtmlString加载本地html文件.加载的页面包含指向其他本地html文件的链接以及使用互联网的真实链接.
我添加了一个后退按钮:
if([self.webView canGoBack])[self.webView goBack];
这工作正常,除了它不能识别加载loadHtmlString的原始页面.
例如,如果我导航:
local - > local - > web
local X local < - web(第一个返回工作,下一个什么都不做.)
如何让webview识别原始页面,以便后退按钮也适用于它?我能以某种方式将它添加到webview的历史中吗?
提前致谢!
我知道这已经被问了很多次,我已阅读相当 一个 小 问题 ,并用Google搜索,但没有成功,到目前为止天。
我只想在桌面应用程序中加载一个本地 html 文件,事实是这个项目我需要一个 JS 库,其中大部分已经作为网页完成(css、js 和 html,不需要服务器端处理)。我不想强制应用程序从互联网服务器加载网页,以免强迫用户连接互联网。不用说,我在 Swift 和苹果开发方面完全没有经验。
现在这是我遇到的问题:
关于参数的 ide 抱怨,我似乎无法理解它们。
作为参考,这里是我最新代码的片段:
class AppDelegate: NSObject, NSApplicationDelegate
{
@IBOutlet weak var window: NSWindow!
@IBOutlet weak var webView: WebView!
typealias NSSize = CGSize
func applicationDidFinishLaunching(aNotification: NSNotification?)
{
self.window.title = "Chess Study Room"
var try1 = "main.html";
println(try1);
var try2 = NSURL(string: try1)!;
println(try2);
var try3 =
NSBundle.URLForResource("main", withExtension: "html", subdirectory: "web", inBundleWithURL: try2);
println(try3);
var try4 = NSBundle.pathForResource("main", ofType: "html", inDirectory: "web");
println(try4);
var …Run Code Online (Sandbox Code Playgroud) 我正在开发一个iOS应用程序,我想在其中加载HTML文件UIWebView,我的html文件路径如下所示,
iPhone HTML文件路径:
/var/mobile/Applications/65A8E000-21A6-429E-90A0-6BF03BAB3EA5/SarkBuilderApp.app/SarkBuilerHtmlFile_new.html
Run Code Online (Sandbox Code Playgroud)
我想加载这个iPhone设备的HTML文件路径UIWebView.
我怎样才能做到这一点?
非常感谢您的快速回答.让我解释一下我的基本要求,我正在开发一个iOS应用程序,其中我的要求是填充屏幕上的某些字段并生成.pdf文件.
为此,我采用了一个预先定义的HTML表单,之后我更新了.html文件并通过以下代码保存:
NSString *fileName = @"new_file_htmlfile.html";
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *html_file_name_location = [documentsDirectory stringByAppendingPathComponent:fileName];
NSError *error;
// Write the file
[data writeToFile:html_file_name_location atomically:YES
encoding:NSUTF8StringEncoding error:&error];
Run Code Online (Sandbox Code Playgroud)
通过这样做,我已经生成了新的HTML文件,我已经从代码中读取了文件路径.iPhone设备路径是:
/var/mobile/Applications/65A8E000-21A6-429E-90A0-6BF03BAB3EA5/SarkBuilderApp.app/SarkBuilerHtmlFile_new.html
Run Code Online (Sandbox Code Playgroud)
iPhone模拟器路径是:
/Users/rightwaysolution/Library/Application Support/iPhone Simulator/6.1/Applications/20748991-EE5C-44FE-ACFF-D93542FCF95B/Documents/new_file_htmlfile.html
Run Code Online (Sandbox Code Playgroud)
现在我正在尝试在我的UIWebView上加载iPhone设备HTML文件,以便我可以将其转换为.pdf.
你能告诉我如何访问该文件吗?