zoukankan      html  css  js  c++  java
  • webview重新加载(reload)或者发起 redirect request导致js和objc代码之间的bridge失联解决方案(亲测有效)

    - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { 
    //isNotFirstLoad' marks if it is the fisrt load.

    //isNotFirstLoad是代表当前这个webview是不是已经加载了一次request if (isNotFirstLoad) { //如果不加上这个判断,后面出现的loadRequest函数的调用就会导致出现死循环 //create an new webview CGRect frame = _myWebView.frame; [_myWebView removeFromSuperview]; _myWebView = [[EasyJSWebView alloc] initWithFrame:frame]; [self.view addSubview:_myWebView]; //init the new webview _webView.delegate = self; javaScriptInterface* interface = [javaScriptInterface new]; [self.webView addJavascriptInterfaces:interface WithName:@"interface"]; [_myWebView loadRequest:request]; //reset the firstload flag to load the new request isNotFirstLoad = NO; //返回No,则不加载本方法传入的的request return NO; } isNotFirstLoad = YES; return YES; //YES if the web view should begin loading content; otherwise, NO .

    }

  • 相关阅读:
    log4j
    hashContext
    sql语句
    css样式
    作业七:(二)疑问解答
    作业七:(1)翻译
    结对编程作业
    软件优缺点评价(补交)
    C#程序分析
    VS2013安装及测试练习
  • 原文地址:https://www.cnblogs.com/linusflow/p/8688314.html
Copyright © 2011-2022 走看看