• <bdo id='6w7wW'></bdo><ul id='6w7wW'></ul>

        <tfoot id='6w7wW'></tfoot>

        <small id='6w7wW'></small><noframes id='6w7wW'>

        <legend id='6w7wW'><style id='6w7wW'><dir id='6w7wW'><q id='6w7wW'></q></dir></style></legend>
        <i id='6w7wW'><tr id='6w7wW'><dt id='6w7wW'><q id='6w7wW'><span id='6w7wW'><b id='6w7wW'><form id='6w7wW'><ins id='6w7wW'></ins><ul id='6w7wW'></ul><sub id='6w7wW'></sub></form><legend id='6w7wW'></legend><bdo id='6w7wW'><pre id='6w7wW'><center id='6w7wW'></center></pre></bdo></b><th id='6w7wW'></th></span></q></dt></tr></i><div id='6w7wW'><tfoot id='6w7wW'></tfoot><dl id='6w7wW'><fieldset id='6w7wW'></fieldset></dl></div>
      1. 使用 JavaScript 的 UIWebView CSS 注入

        UIWebView CSS injection using JavaScript(使用 JavaScript 的 UIWebView CSS 注入)

      2. <legend id='4iwG2'><style id='4iwG2'><dir id='4iwG2'><q id='4iwG2'></q></dir></style></legend>

          • <i id='4iwG2'><tr id='4iwG2'><dt id='4iwG2'><q id='4iwG2'><span id='4iwG2'><b id='4iwG2'><form id='4iwG2'><ins id='4iwG2'></ins><ul id='4iwG2'></ul><sub id='4iwG2'></sub></form><legend id='4iwG2'></legend><bdo id='4iwG2'><pre id='4iwG2'><center id='4iwG2'></center></pre></bdo></b><th id='4iwG2'></th></span></q></dt></tr></i><div id='4iwG2'><tfoot id='4iwG2'></tfoot><dl id='4iwG2'><fieldset id='4iwG2'></fieldset></dl></div>
            <tfoot id='4iwG2'></tfoot>
              <tbody id='4iwG2'></tbody>

                <bdo id='4iwG2'></bdo><ul id='4iwG2'></ul>

                <small id='4iwG2'></small><noframes id='4iwG2'>

                  本文介绍了使用 JavaScript 的 UIWebView CSS 注入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试将本地 css 文件注入完成加载网站(如 google 等)的 UIWebView.

                  I'm trying to inject a local css file into an UIWebView that finished loading website such as google etc.

                  我正在尝试使用 JavaScript,但没有成功.

                  I'm trying with JavaScript but with no success.

                  
                  - (void)webViewDidFinishLoad:(UIWebView *)webView {
                      NSString *cssPath = [[NSString alloc] initWithString:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"styles.css"]];
                      NSURL *baseURL = [NSURL fileURLWithPath:cssPath];
                  
                      NSString *js = [NSString stringWithFormat:@"var fileref = document.createElement('link');
                                      fileref.setAttribute('rel', 'stylesheet');
                                      fileref.setAttribute('type', 'text/css');
                                      fileref.setAttribute('href', %@);", baseURL];
                  
                      [webView stringByEvaluatingJavaScriptFromString:js];
                  }
                  

                  谢谢,

                  推荐答案

                  要将 javascript 注入 Web 视图,您必须在 html 中显式编写.

                  To inject javascript into a web view you must explicitly write in the html.

                  我在 javascript scrollTo 函数中写了一个例子:

                  An example of this is here where I wrote in a javascript scrollTo function:

                  - (void)webViewDidFinishLoad:(UIWebView *)webView {
                   [webView stringByEvaluatingJavaScriptFromString:@"var script = document.createElement('script');"  
                   "script.type = 'text/javascript';"  
                   "script.text = "function myFunction() { "  
                   "window.scrollTo(100,100)"
                   "}";"  
                   "document.getElementsByTagName('head')[0].appendChild(script);"];  
                  
                   [webView stringByEvaluatingJavaScriptFromString:@"myFunction();"];}
                  

                  此代码将整个脚本标签和 myFunction 写入 HTML 的头部

                  This code writes the entire script tags and the myFunction into the head of the HTML

                  这篇关于使用 JavaScript 的 UIWebView CSS 注入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Getting an NSArray of a single attribute from an NSArray(从 NSArray 获取单个属性的 NSArray)
                  ImageIO: lt;ERRORgt; JPEG Corrupt JPEG data: premature end of data segment iphone - how to catch this?(ImageIO:lt;错误gt;JPEG 损坏的 JPEG 数据:iphone 数据段过早结束 - 如何捕捉到这个?)
                  Xcode iOS organizer submit to app store yields quot;The archive is invalidquot; error(Xcode iOS 管理器提交到应用商店产生“存档无效;错误)
                  MFMessageComposeViewController alloc returns nil(MFMessageComposeViewController alloc 返回 nil)
                  Mobile Device Management with iPhone(使用 iPhone 进行移动设备管理)
                  iPhone: How to allow multiple selection in tabelview for a custom cell?(iPhone:如何允许在自定义单元格的表格视图中进行多项选择?)
                  <i id='H2HMJ'><tr id='H2HMJ'><dt id='H2HMJ'><q id='H2HMJ'><span id='H2HMJ'><b id='H2HMJ'><form id='H2HMJ'><ins id='H2HMJ'></ins><ul id='H2HMJ'></ul><sub id='H2HMJ'></sub></form><legend id='H2HMJ'></legend><bdo id='H2HMJ'><pre id='H2HMJ'><center id='H2HMJ'></center></pre></bdo></b><th id='H2HMJ'></th></span></q></dt></tr></i><div id='H2HMJ'><tfoot id='H2HMJ'></tfoot><dl id='H2HMJ'><fieldset id='H2HMJ'></fieldset></dl></div>
                    <tbody id='H2HMJ'></tbody>
                    <tfoot id='H2HMJ'></tfoot>

                    • <bdo id='H2HMJ'></bdo><ul id='H2HMJ'></ul>

                        1. <small id='H2HMJ'></small><noframes id='H2HMJ'>

                          • <legend id='H2HMJ'><style id='H2HMJ'><dir id='H2HMJ'><q id='H2HMJ'></q></dir></style></legend>