ios - Javascript working on mac(chrome) but not in UIWebView -
document.getelementbyid('svin').value = "1fmdu34x6ruc10442"
is running within google chrome console on mac on webpage not within ipad uiwebview using:
[webview stringbyevaluatingjavascriptfromstring:javascript]; there no error log, can run javascripts on other websites similarly, there no problem in code. what possible reason , workaround?
i checked case , it's true code not working.
but created experiment - delayed evaluation. action worked.
what i've done first was:
- (void) test { [webview stringbyevaluatingjavascriptfromstring:javascript]; } then used:
[self performselector:@selector(test) withobject:nil afterdelay:1]; and worked. suppose code evaluating before dom ready.
there many ways prevent such situation.
let's don't have access site, server-side javascripts (e.g. $(document).ready() {}) no go.
from ios can implement completion callback webview:
- (void)webviewdidfinishload:(uiwebview *)webview { [webview stringbyevaluatingjavascriptfromstring:javascript]; } don't forget delegating webview , adding protocol parent class:
webview.delegate = self; i've checked , worked. in case it's not working - it's wrong site makes dom not ready if ios webview thinks it's finished. if so, combine 2 resolutions i've described - evaluate js after delay in webviewdidfinishload callback:
- (void)webviewdidfinishload:(uiwebview *)webview { [self performselector:@selector(yourmethodwithjs) withobject:nil afterdelay:1]; } i realize lastly advice it's not elegant approach that't have if you're not in charge of fixing site.
javascript ios uiwebview
No comments:
Post a Comment