how to use javascript in uiwebview to get the clicked button id?

前端 未结 2 1177
时光说笑
时光说笑 2021-01-15 17:01

This Time i want to know how to determine which button is click in UIWebView.....

    appDelegate.mystring = [[NSMutableString string]init];
    NSString *b         


        
2条回答
  •  粉色の甜心
    2021-01-15 17:42

    The only method I know is by implementing webView:shouldStartLoadWithRequest:navigationType method of UIWebViewDelegate protocol. The required steps are as follows:

    1) Create a new class subclassed from NSObject named, say, MyWebViewDelegate. You can implement only that method:

    -(BOOL)webView:(UIWebView*)webView
           sholdStartLoadWithRequest:(NSURLRequest *)request
           navigationType:(UIWebViewNavigationType)navigationType
    {
        NSLog(@"%@", [[request URL] relativePath]);
    }
    

    2) Create instance of delegate in your code and set it as a delegate of UIWebView before loading page:

    MyWebViewDelegate *mydelegate = [[MyWebViewDelegate alloc] init];
    mywebview.delegate = mydelegate;
    

    3) And then try to debug. Try to put breakpoint inside ..sholdStartLoadWithRequest:.. method and ensure that you application stops in that breakpoint. Maybe you shold do a little redesign of you HTML webpage to achieve this. After that try to distinguish different buttons by value of request parameter.

提交回复
热议问题