HTML不尊重UIWebView中的.CSS文件

时间:2023-01-16 20:23:26

I am trying to load html page in WKWebView which is linked to external javascript and css files. My web view shows me the html page but it does not seem like that its respecting css file values. Can anyone please suggest me as to what am I doing wrong here. Following my code to add html page in WKWebView:

我正在尝试在WKWebView中加载html页面,该页面链接到外部javascript和css文件。我的Web视图向我显示了html页面,但它似乎不是它尊重css文件值。任何人都可以建议我在这里做错了什么。按照我的代码在WKWebView中添加html页面:

  override func viewDidLoad() {
    super.viewDidLoad()

    let path = NSBundle.mainBundle().pathForResource("index", ofType: "html");
    let htmlString = String.stringWithContentsOfFile(path, encoding: NSUTF8StringEncoding, error: nil);

    self.webView.loadHTMLString(htmlString, baseURL: NSURL.fileURLWithPath(NSBundle.mainBundle().bundlePath));

  }

Also, here is the project structure where .css, .js and .html files re added.

此外,这里是重新添加.css,.js和.html文件的项目结构。

HTML不尊重UIWebView中的.CSS文件

Any help would be appreciated.

任何帮助,将不胜感激。

1 个解决方案

#1


0  

The problem is that the WKWebView renders page content inside a sandbox process that cannot access files in your application bundle. This effectively means that file:// URLs do not work.

问题是WKWebView在沙箱进程中呈现无法访问应用程序包中的文件的页面内容。这实际上意味着file:// URL不起作用。

I ended up including a small web server in my application to make it easier to serve content to the WKWebView.

我最终在我的应用程序中包含了一个小型Web服务器,以便更轻松地为WKWebView提供内容。

#1


0  

The problem is that the WKWebView renders page content inside a sandbox process that cannot access files in your application bundle. This effectively means that file:// URLs do not work.

问题是WKWebView在沙箱进程中呈现无法访问应用程序包中的文件的页面内容。这实际上意味着file:// URL不起作用。

I ended up including a small web server in my application to make it easier to serve content to the WKWebView.

我最终在我的应用程序中包含了一个小型Web服务器,以便更轻松地为WKWebView提供内容。