Comments (10)
It's the way how WebViewJavaScriptBridge works.
As you can see it here: https://github.com/marcuswestin/WebViewJavascriptBridge/blob/master/WebViewJavascriptBridge/WebViewJavascriptBridge.m#L79
It uses JS to redirect it's own iFrame, that will be processed by native Objective-C code in this method:
https://github.com/marcuswestin/WebViewJavascriptBridge/blob/master/WebViewJavascriptBridge/WebViewJavascriptBridge.m#L142
03.05.2012, в 16:21, roamerxv написал(а):
I code the test program.
the .h file is//
// ViewController.h
// test
//
// Created by remote roamer on 12-5-3.
// Copyright (c) 2012年 MyCompanyName. All rights reserved.
//#import <UIKit/UIKit.h>
#import "WebViewJavascriptBridge.h"
#import "AppDelegate.h"@Class AppDelegate;
@interface ViewController : UIViewController
{
IBOutlet UIWebView * webView;
}@Property(retain,nonatomic) UIWebView * webView;
@Property(retain,nonatomic) WebViewJavascriptBridge * javascriptBridge;
@Property(nonatomic,retain) NSBundle* bundle ;
the .m file :
//
// ViewController.m
// test
//
// Created by remote roamer on 12-5-3.
// Copyright (c) 2012年 MyCompanyName. All rights reserved.
//#import "ViewController.h"
@interface ViewController ()
@implementation ViewController
@synthesize webView;
@synthesize bundle;
@synthesize javascriptBridge;-(void) javascriptBridge:(WebViewJavascriptBridge *)bridge receivedMessage:(NSString *)message fromWebView:(UIWebView *)webView
{}
-(void) webViewDidStartLoad:(UIWebView *)webView
{
NSLog(@"loading html start");
//[MBProgressHUD showHUDAddedTo:self.webView animated:YES];
}-(void) webViewDidFinishLoad:(UIWebView *)webView
{
NSLog(@"load html finish.");
//[MBProgressHUD hideHUDForView:self.webView animated:YES];
}-(void) webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
NSLog(@"load html error:%@",error);
//[MBProgressHUD hideHUDForView:self.webView animated:YES];
}
(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
NSLog(@"initWithNibName");
//self.javascriptBridge = [WebViewJavascriptBridge javascriptBridgeWithDelegate: (AppDelegate *)([UIApplication sharedApplication]).delegate];
self.javascriptBridge = [WebViewJavascriptBridge javascriptBridgeWithDelegate:self];}
return self;
}(void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"viewDidLoad");//self.webView.delegate = self;
self.webView.delegate = self.javascriptBridge;
self.bundle = [NSBundle mainBundle];
[webView loadHTMLString:@"aaa" baseURL:[NSURL fileURLWithPath:[bundle bundlePath]]];// Do any additional setup after loading the view, typically from a nib.
}(void)viewDidUnload
{[super viewDidUnload];
// Release any retained subviews of the main view.
}(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}When I run it , the logger info in console is :
2012-05-03 20:11:06.777 test[14860:f803] initWithNibName
2012-05-03 20:11:06.791 test[14860:f803] viewDidLoad
2012-05-03 20:11:06.813 test[14860:f803] loading html start
2012-05-03 20:11:06.836 test[14860:f803] loading html start
2012-05-03 20:11:06.837 test[14860:f803] load html finish.
2012-05-03 20:11:06.840 test[14860:f803] load html finish.Why the html connent loaded twice?
Reply to this email directly or view it on GitHub:
#10
from webviewjavascriptbridge.
thank you for replay。
It's mean that html content be loaded twice can not avoid ?
from webviewjavascriptbridge.
It doesn't get loaded twice - only almost empty iframe changes it's location.
03.05.2012, в 21:36, [email protected] написал(а):
thank you for replay。
It's mean that html content be loaded twice can not avoid ?
Reply to this email directly or view it on GitHub:
#10 (comment)
from webviewjavascriptbridge.
But I not use some empty iframe in my code. Just only one webView in the view that designed by xib file
from webviewjavascriptbridge.
Maybe it loads multiple resources, eg favicon.ico?
-- while mobile
On May 3, 2012, at 5:21 AM, [email protected] wrote:
I code the test program.
the .h file is//
// ViewController.h
// test
//
// Created by remote roamer on 12-5-3.
// Copyright (c) 2012年 MyCompanyName. All rights reserved.
//#import <UIKit/UIKit.h>
#import "WebViewJavascriptBridge.h"
#import "AppDelegate.h"@Class AppDelegate;
@interface ViewController : UIViewController
{
IBOutlet UIWebView * webView;
}@Property(retain,nonatomic) UIWebView * webView;
@Property(retain,nonatomic) WebViewJavascriptBridge * javascriptBridge;
@Property(nonatomic,retain) NSBundle* bundle ;
the .m file :
//
// ViewController.m
// test
//
// Created by remote roamer on 12-5-3.
// Copyright (c) 2012年 MyCompanyName. All rights reserved.
//#import "ViewController.h"
@interface ViewController ()
@implementation ViewController
@synthesize webView;
@synthesize bundle;
@synthesize javascriptBridge;-(void) javascriptBridge:(WebViewJavascriptBridge *)bridge receivedMessage:(NSString *)message fromWebView:(UIWebView *)webView
{}
-(void) webViewDidStartLoad:(UIWebView *)webView
{
NSLog(@"loading html start");
//[MBProgressHUD showHUDAddedTo:self.webView animated:YES];
}-(void) webViewDidFinishLoad:(UIWebView *)webView
{
NSLog(@"load html finish.");
//[MBProgressHUD hideHUDForView:self.webView animated:YES];
}-(void) webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
NSLog(@"load html error:%@",error);
//[MBProgressHUD hideHUDForView:self.webView animated:YES];
}
(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
NSLog(@"initWithNibName");
//self.javascriptBridge = [WebViewJavascriptBridge javascriptBridgeWithDelegate: (AppDelegate *)([UIApplication sharedApplication]).delegate];
self.javascriptBridge = [WebViewJavascriptBridge javascriptBridgeWithDelegate:self];}
return self;
}(void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"viewDidLoad");//self.webView.delegate = self;
self.webView.delegate = self.javascriptBridge;
self.bundle = [NSBundle mainBundle];
[webView loadHTMLString:@"aaa" baseURL:[NSURL fileURLWithPath:[bundle bundlePath]]];// Do any additional setup after loading the view, typically from a nib.
}(void)viewDidUnload
{[super viewDidUnload];
// Release any retained subviews of the main view.
}(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}When I run it , the logger info in console is :
2012-05-03 20:11:06.777 test[14860:f803] initWithNibName
2012-05-03 20:11:06.791 test[14860:f803] viewDidLoad
2012-05-03 20:11:06.813 test[14860:f803] loading html start
2012-05-03 20:11:06.836 test[14860:f803] loading html start
2012-05-03 20:11:06.837 test[14860:f803] load html finish.
2012-05-03 20:11:06.840 test[14860:f803] load html finish.Why the html connent loaded twice?
Reply to this email directly or view it on GitHub:
#10
from webviewjavascriptbridge.
Hi.I used the WeViewbJavascriptBridge in my project , then found the html reload twice .
So I write the simple test project , not used any resources and faviicon.ico that just only a simple window .
project is uploaded .
https://github.com/roamerxv/WebJavascriptBridgeTester
Can u help me to find the problems? thank you very much.
from webviewjavascriptbridge.
Im sorry, but I don't have time to debug this right now. I believe that event may fire every time you send a message, in which case the second load may be the JavaScript sending the "I'm ready" message.
-- while mobile
On May 3, 2012, at 7:47 PM, [email protected] wrote:
Hi.I used the WeViewbJavascriptBridge in my project , then found the html reload twice .
So I write the simple test project , not used any resources and faviicon.ico that just only a simple window .
project is uploaded .
https://github.com/roamerxv/WebJavascriptBridgeTesterCan u help me to find the problems? thank you very much.
Reply to this email directly or view it on GitHub:
#10 (comment)
from webviewjavascriptbridge.
ok。tank for your replay.
I take it by myself
from webviewjavascriptbridge.
Sorry :( best of luck!!
-- while mobile
On May 4, 2012, at 4:45 AM, [email protected] wrote:
ok。tank for your replay.
I take it by myself
Reply to this email directly or view it on GitHub:
#10 (comment)
from webviewjavascriptbridge.
Closing - feel free to reopen.
from webviewjavascriptbridge.
Related Issues (20)
- Web view is blank after creating the bridge object HOT 1
- iOS14.6 WebViewJavascriptBridge not work but iOS14.3 works HOT 1
- Hello
- Why don't work in iPad Air (14.1) ? HOT 2
- nice
- iOS 15.4 js 交互不走decidePolicyFor 这个代理方法了 HOT 2
- Mac OSX app Packages printed in version 10.15 and above crashed in system 10.14 and below, so far the problem has not been located HOT 1
- nice
- nice
- 我已经重构了这个库,10分钟就能完成接入,也许可以帮助你. HOT 2
- 按照README 第四步拷贝的js代码可能不起作用 HOT 1
- failed assertion `Draw Errors Validation
- Mambamessage
- Installed with CocoaPods in Xcode 15 beta 6 can not build module 'WebKit' HOT 9
- I think that if you no longer maintain this library, then it is recommended that you make this warehouse archived, rather than leave it to grow grass!
- JSBridge H5调用原生的方法,频繁调用的性能优化
- iOS17.1.1 收不到回调 HOT 8
- I
- Invalid string representation for a specification: `WebViewJavascriptBridge(WK) (6.1.0)
- Unblock iphone 8 plus
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from webviewjavascriptbridge.