gpt4 book ai didi

javascript - 如何判断 stringByEvaluatingJavaScriptFromString 求值过程完成?

转载 作者:行者123 更新时间:2023-11-28 22:28:40 24 4
gpt4 key购买 nike

我正在将 html 文件读入 UIWebview。在 webViewDidFinishLoad 中,我正在为水平滚动执行 javascript 函数。下面的代码工作正常。但我无法预测 javascript 函数何时完成。

在可见的 webview 中首先加载 html 文件然后脚本运行。所以我可以确定 javascript 在 webViewDidFinishLoad 中完成。

- (void)webViewDidFinishLoad:(UIWebView *)webView
{

NSString *scriptString =@"javascript:function initialize() { var eelam = document.getElementsByTagName('body')[0]; var ourH = window.innerHeight;var ourW = window.innerWidth; var fullH = eelam.offsetHeight; var pageCount = Math.ceil(fullH/ourH)+1; var padval = parseInt((screen.width*10)/100);var currentPage = 0; var newW = pageCount*ourW;eelam.style.height = (ourH - 30)+'px';eelam.style.width = (newW)+'px';eelam.style.webkitColumnGap = '5px'; eelam.style.margin = '25px'; eelam.style['margin-left']='2px';eelam.style.webkitColumnCount = pageCount; window.interface.setPageCount(pageCount);window.interface.setColumnWidth(screen.width);window.interface.setContent(eelam);window.interface.setColumnGap(padval);};";

// set font
NSString *jsString = [[NSString alloc] initWithFormat:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '%d%%'",
textFontSize];

[mywebview stringByEvaluatingJavaScriptFromString:scriptString];

[mywebview stringByEvaluatingJavaScriptFromString:@"javascript:initialize()"];

[mywebview stringByEvaluatingJavaScriptFromString:jsString];

// scroll disable
UIView* row = nil;
for(row in webView.subviews){
if([row isKindOfClass:[UIScrollView class] ]){
UIScrollView* scrollRow = (UIScrollView*) row;
scrollRow.scrollEnabled = NO;
scrollRow.bounces = NO;
scrollRow.pagingEnabled=YES;
}
}

// this code is also not use to handle my issue
if ([[mywebview stringByEvaluatingJavaScriptFromString:@"document.readyState"] isEqualToString:@"complete"]) {

}


}

请多多指教

提前致谢,

最佳答案

该函数不是异步的。它在从评估函数返回值之前完成。

关于javascript - 如何判断 stringByEvaluatingJavaScriptFromString 求值过程完成?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18124773/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com