我有一个HTML页面。在其中我必须使用文档目录URL加载图像。这是html和javascript。
<html>
<head>
<script type="text/javascript">
function fetchObjDetails(scanImageLeftURL, scanImageRightURL)
{
/* left image */
var leftImg = new Image;
leftImg.onload = function() {
document.getElementById('left_foot').src = this.src;
}
leftImg.src = scanImageLeftURL;
/* right image */
var rightImg = new Image;
rightImg.onload = function() {
document.getElementById('right_foot').src = this.src;
}
rightImg.src = scanImageRightURL;
}
</script>
</head>
<body>
<div class="container padall">
<img alt="Left Foot" id="left_foot" src="" width="30%" />
<img alt="Right Foot" id="right_foot" src="" width="30%" />
</div>
</body>
</html>
这是我用来触发函数的客观c代码。
-(void)viewDidLoad
{
[super viewDidLoad];
NSString *fullURL = @"some live url";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
webFormView.delegate=self;
[webFormView loadRequest:requestObj];
}
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
NSString *leftImgURL = @"/var/mobile/Containers/Data/Application/95736371-EA3D-475D-942D-835A037F8795/Documents/LeftImage_1454405366000.jpg";
NSString *rightImgURL = @"/var/mobile/Containers/Data/Application/95736371-EA3D-475D-942D-835A037F8795/Documents/RightImage_1454405366000.jpg";
NSString *script = [NSString stringWithFormat:@"fetchObjDetails('%@','%@')", leftImgURL, rightImgURL];
[webView stringByEvaluatingJavaScriptFromString:script];
}
但是我没有在html端获得任何图像。有人可以告诉我这是正确的过程吗?