Giter Site home page Giter Site logo

Comments (10)

implementation avatar implementation commented on September 28, 2024

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 ;

@EnD

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 ()

@EnD

@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;
    }

@EnD

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.

roamerxv avatar roamerxv commented on September 28, 2024

thank you for replay。

It's mean that html content be loaded twice can not avoid ?

from webviewjavascriptbridge.

implementation avatar implementation commented on September 28, 2024

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.

roamerxv avatar roamerxv commented on September 28, 2024

But I not use some empty iframe in my code. Just only one webView in the view that designed by xib file

from webviewjavascriptbridge.

marcuswestin avatar marcuswestin commented on September 28, 2024

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 ;

@EnD

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 ()

@EnD

@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;
    }

@EnD

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.

roamerxv avatar roamerxv commented on September 28, 2024

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.

marcuswestin avatar marcuswestin commented on September 28, 2024

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/WebJavascriptBridgeTester

Can 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.

roamerxv avatar roamerxv commented on September 28, 2024

ok。tank for your replay.
I take it by myself

from webviewjavascriptbridge.

marcuswestin avatar marcuswestin commented on September 28, 2024

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.

marcuswestin avatar marcuswestin commented on September 28, 2024

Closing - feel free to reopen.

from webviewjavascriptbridge.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.