• <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 注入

        时间:2023-10-22

      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 注入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:过渡到 iOS 7:在 iPad 上查看的 jQuery/iPhone Web 应用程序的正确视口设置 下一篇:UIWebView 将 Objective C 暴露给 JavaScript

                  相关文章

                  <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>
                  <tfoot id='H2HMJ'></tfoot>

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

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

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