简体   繁体   English

有什么方法可以在1个UIWebview中加载.js文件并在iOS中的其他UIWebviews实例中使用它?

[英]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.

相关问题 我们可以将一个.js文件的变量用于其他.js文件吗? - Can we use variable of one .js file to other .js file? 有没有办法动态加载本地JS文件? - Is there any way to load a local JS file dynamically? reactjs-我们可以访问存储在其他文件中的react组件中的js var吗? - reactjs - can we access js var in react component which is stored in other file? 有什么方法可以将 email 发送给注册用户 - is there any way by which we can send email to the registered user 有什么方法可以将普通的 object 转换为 class object? - Is there any way in which we can convert plain object to class object? 有什么方法可以在dynmodb中创建关系 - Is there any way by which we can create relationship in dynmodb 有什么办法可以关闭js在IE中打开的其他标签吗? - Is there any way to close other tabs which opened by js in IE…? 我们可以将任何类型的javascript代码用作外部.js文件,还是有时需要将其放置在 <head> ? - Can we use any type of javascript code as a external .js file or sometime it's necessary to place in <head>? 我们可以使用 System.import 或 import() function 到任何 Javascript 文件还是仅使用单个模块特定的 js? - Can we use System.import or import() function to any Javascript file or only Single module specific js? 在IOS的UIWebview中引用js和CSS文件? - Refer js and css file in UIWebview in IOS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM