iphone - shouldStartLoadWithRequest doesn't run stringByEvaluatingJavaScriptFromString method -


i trying run code below in webview's shouldstartloadwithrequest delegate method doesn't make changes.

- (bool)webview:(uiwebview *)webview shouldstartloadwithrequest:(nsurlrequest *)request navigationtype:(uiwebviewnavigationtype)navigationtype{     nslog(@"webview shouldstartloadingwithrequest");     [self.webview stringbyevaluatingjavascriptfromstring:[nsstring stringwithformat:@"document.execcommand('bold', false,null)"]];     return true; } 

there no error, prints nslog , everything in method works great except "stringbyevaluatingjavascriptfromstring" method.

but if try make text bold in function, example ibaction method, works fine.

-(ibaction)boldclick:(id)sender {     [self.webview stringbyevaluatingjavascriptfromstring:[nsstring stringwithformat:@"document.execcommand('bold', false,null)"]]; } 

actually, company's special application , uiwebview not show web pages. using show custom html pages. need make in "shouldstartloadwithrequest" because trying run objective-c method javascript.

update

- (bool)webview:(uiwebview *)webview shouldstartloadwithrequest:(nsurlrequest *)request navigationtype:(uiwebviewnavigationtype)navigationtype{      // break apart request url     nsstring *requeststring = [[request url] absolutestring];     nsarray *components = [requeststring componentsseparatedbystring:@":"];       // check protocol     if ([components count]==3)     {         [self makeboldtext];         return no;     }     else     {         return true;     } }  -(void)makeboldtext {     [self.webview stringbyevaluatingjavascriptfromstring:[nsstring stringwithformat:@"document.execcommand('bold', false,null)"]]; } 

the doc says method webview:shouldstartloadwithrequest: sent before web view begins loading frame. after return yes in method, web view starts loading request. javascript execute have no effect, because new page loaded after js call.

you can use webviewdidfinishload: method execute javascript after page finishes load. or if want trigger js clicking on link, can use shouldstartloadwithrequest return no it.


Comments