• <legend id='sahkL'><style id='sahkL'><dir id='sahkL'><q id='sahkL'></q></dir></style></legend>
    1. <tfoot id='sahkL'></tfoot>

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

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

        如何在目标 C 中调用 JavaScript 函数

        How to call JavaScript Function in objective C(如何在目标 C 中调用 JavaScript 函数)
        <legend id='04yKl'><style id='04yKl'><dir id='04yKl'><q id='04yKl'></q></dir></style></legend>

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

            <small id='04yKl'></small><noframes id='04yKl'>

              <bdo id='04yKl'></bdo><ul id='04yKl'></ul>
                <tbody id='04yKl'></tbody>
            • <tfoot id='04yKl'></tfoot>

                  本文介绍了如何在目标 C 中调用 JavaScript 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我是 Objective C 的新程序员.我在 Objective C 中添加了一些 html 文件.在这个 html 文件中包含简单的 javascript 函数.我需要通过目标 C 代码调用该函数.我用谷歌尝试了很多时间.但我找不到真正的方法来做到这一点.波纹管包含 html 文件:

                  I am new programmer to objective C. I added some html file to Objective C. In this html file contains simple javascript function. I need to call that Function through thw objective C code. I tried lot of time by using google. But I could not find real way to do it. Bellow Contains html File :

                  <!DOCTYPE html>
                  <html>
                      <head>
                          <script>
                              function myFunction()
                              {
                                  alert("Hello World!");
                              }
                              </script>
                      </head>
                  
                      <body>
                          <button onclick="myFunction()">Try it</button>
                      </body>
                  </html>
                  

                  我这样调用这个函数:它是正确的还是错误的??如果错了,该怎么做.请帮忙.

                  I called this function like this : Is it correct or wrong ?? If it wrong, how to do this. Please help.

                  NSString *path;
                  NSBundle *thisBundle = [NSBundle mainBundle];
                  path = [thisBundle pathForResource:@"first" ofType:@"html"];
                  NSURL *instructionsURL = [NSURL fileURLWithPath:path];
                  [webView loadRequest:[NSURLRequest requestWithURL:instructionsURL]];
                  
                   NSString * jsCallBack = [NSString stringWithFormat:@"myFunction()"];
                   [webView stringByEvaluatingJavaScriptFromString:jsCallBack];
                  
                  [webView stringByEvaluatingJavaScriptFromString:@"myFunction()"];
                  

                  推荐答案

                  NSString *path;
                  NSBundle *thisBundle = [NSBundle mainBundle];
                  path = [thisBundle pathForResource:@"first" ofType:@"html"];
                  NSURL *instructionsURL = [NSURL fileURLWithPath:path];
                  [webView loadRequest:[NSURLRequest requestWithURL:instructionsURL]];
                  
                   NSString * jsCallBack = [NSString stringWithFormat:@"myFunction()"];
                   [webView stringByEvaluatingJavaScriptFromString:jsCallBack];
                  
                  [webView stringByEvaluatingJavaScriptFromString:@"myFunction()"];
                  

                  如果所有这些代码都是从一个地方调用的,那么它将无法正常工作,因为页面加载是异步的,并且带有 JavaScript 代码的页面此时还没有准备好.尝试在 UIWebViewDelegate 回调方法中调用此方法 [webView stringByEvaluatingJavaScriptFromString:@"myFunction()"]; –webViewDidFinishLoad:

                  If all this code called from single place, than it won't work, because page load is asynchronous and page with JavaScript code is not ready at that moment. Try to call this methods [webView stringByEvaluatingJavaScriptFromString:@"myFunction()"]; in UIWebViewDelegate callback method –webViewDidFinishLoad:

                  这篇关于如何在目标 C 中调用 JavaScript 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  EAAccessory/EASession teardown during background(EAAccessory/EASession 在后台拆除)
                  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 数据段过早结束 - 如何捕捉到这个?)
                  How to get indexPath.row of tableView which is currently being displayed?(如何获取当前正在显示的 tableView 的 indexPath.row?)
                  Xcode iOS organizer submit to app store yields quot;The archive is invalidquot; error(Xcode iOS 管理器提交到应用商店产生“存档无效;错误)
                  MFMessageComposeViewController alloc returns nil(MFMessageComposeViewController alloc 返回 nil)
                1. <small id='QkGWw'></small><noframes id='QkGWw'>

                  • <bdo id='QkGWw'></bdo><ul id='QkGWw'></ul>
                        1. <tfoot id='QkGWw'></tfoot>

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