Tuesday, 10 September 2013

How to call the html function while loading the html file in webview?

How to call the html function while loading the html file in webview?

I was facing an issue for calling the htmnl function from xcode ,Here i am
writing the code of both Html and objective-c ,
This is html function
<script type="text/javascript">
function load(val)
{
alert(val);
document.getElementById("h_dvid").value=val;
}
</script>
In viewcontroller viewdidload i am calling that function like this,
- (void)viewDidLoad
{
[super viewDidLoad];
web = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 360)];
[web loadRequest:[NSURLRequest requestWithURL:[NSURL
fileURLWithPath:[[NSBundle mainBundle]
pathForResource:@"index"
ofType:@"html"]isDirectory:NO]]];
[self.view addSubview:web];
NSString* str=[NSString stringWithFormat:@"load('%@')",@"hi"];
[web stringByEvaluatingJavaScriptFromString:str];
web.delegate=self;
// Do any additional setup after loading the view, typically from a nib.
}
then i was not getting call the load function due to html file is not
loaded fully so, I had taken a button when i clicked on that button then i
called the html function then its working fine.BUT i need to call HTML
function in viewdidload itself.I am waiting for your answer.

No comments:

Post a Comment