简体   繁体   English

WebView使用本地目录中的所有资源加载HTML页面

[英]WebView load HTML page with all resources from a local directory

I am developing a COCOA application. 我正在开发可可应用程序。 It's a requirement of the application to load HTML page from a local directory. 应用程序需要从本地目录加载HTML页面。 The HTML page includes links to many resources such as images, JavaScript, XML and CSS file. HTML页面包含许多资源的链接,例如图像,JavaScript,XML和CSS文件。 Hence it's more like a local website without any server. 因此,它更像是没有任何服务器的本地网站。 How can I achieve this using WebView control? 如何使用WebView控件实现此目的? I am developing application for Mac OS X. 我正在为Mac OS X开发应用程序。

Any help would be highly appreciated, Farooq- 任何帮助将不胜感激,Farooq-

You can simply use this code - 您可以简单地使用以下代码-

[[yourWebView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:pathOfLocalWebPage]]];

Hope this helps :) 希望这可以帮助 :)

Swift 3: 斯威夫特3:

let urlpath = Bundle.main.path(forResource: "index", ofType: "html");
let requesturl = URL(string: urlpath!)
let request = URLRequest(url: requesturl!)
webView.mainFrame.load(request)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM