3 回答

TA貢獻1951條經(jīng)驗 獲得超3個贊
更改頁面的位置可能會導(dǎo)致以下問題:
所有setInterval和setTimeout立即停止在位置更改上
取消位置更改后,每個innerHTML都不起作用!
你可能會得到其他非常奇怪的錯誤,真的難以診斷......
這里提供的解決方案是:
繼續(xù)使用相同的URL技術(shù)(在js和objective-c上),只需使用iframe更改位置:
var iframe = document.createElement("IFRAME");
iframe.setAttribute("src", "js-frame:myObjectiveCFunction";
document.documentElement.appendChild(iframe);
iframe.parentNode.removeChild(iframe);
iframe = null;

TA貢獻1862條經(jīng)驗 獲得超6個贊
從Objective-C:您可以將字符串中的javascript函數(shù)傳遞給UIWebView。網(wǎng)頁將執(zhí)行它并返回結(jié)果。這樣您就可以傳遞變量并從Javascript中獲取數(shù)據(jù)。
- (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script
例:
NSString *script = @"document.getElementById('myTextField').value";
NSString *output = [myWebView stringByEvaluatingJavaScriptFromString:script];
來自Javascript:將您的數(shù)據(jù)傳遞到URL中。攔截UIWebViewDelegate中的URL請求。通過返回NO獲取數(shù)據(jù)并中止URL請求。
<script>window.location = "url://key1/value1"; </script>
攔截URL請求
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
添加回答
舉報