[英]Is there any way through which we can load .js file in 1 UIWebview and use it in other instance of UIWebviews in iOS?
I am working on a iOS app which draws multiple chart in multiple UIWebviews using a Javascript Library. 我正在开发一个iOS应用程序,该应用程序使用Javascript库在多个UIWebviews中绘制多个图表。 iOS app is passing data to JS library and then that library draws chart by plotting data. iOS应用会将数据传递到JS库,然后该库通过绘制数据来绘制图表。
SO, issue is, in this app we have multiple webviews in which I link "portlet.js" file in each individual webview. 所以,问题是,在这个应用程序中,我们有多个Web视图,其中我在每个单独的Web视图中链接“ portlet.js”文件。 Because of that memory keep increasing drastically as new webview (Charts) is adding and app crashing after going till 4-5 pages of charts. 因此,随着新的Web视图(图表)的添加,内存不断增加,直到4-5页的图表崩溃。 I feel it is because I'm linking seperate "portlet.js" file in each webview. 我感觉是因为我要在每个Web视图中链接单独的“ portlet.js”文件。
So, is there any way by which I can only link "Portlet.js" once in a webview and use it in other webviews ? 那么,有什么方法可以只在Web视图中链接一次“ Portlet.js”并在其他Web视图中使用它?
Thanks in advance 提前致谢
I've used reference (blue) folder in the project named "content". 我在名为“ content”的项目中使用了参考(蓝色)文件夹。 This contains folders like "css", "js", etc. I use it for all WebViews in the app. 它包含“ css”,“ js”等文件夹。我将其用于应用程序中的所有WebView。
let baseUrl = URL(fileURLWithPath: Bundle.main.resourcePath!).appendingPathComponent("content")
let page = """
<html>
<head>
<title>Title</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="css/article_container.css" type="text/css" media="all">
<link rel="stylesheet" href="css/style.css" type="text/css" media="all">
//...
</head>
<body>
<div id="article_container">
//...
</div>
</body>
</html>
"""
// it's important to use `loadHTMLString` and baseUrl param
webView.loadHTMLString(page, baseURL: baseUrl)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.