objective c - Load Javascript files through HTML file on WKWebView in iOS -
i have requirement of loading javascript files through html
file. have structured files in order shown in below screenshot.
html
head tag contains javascript
files call below:
<head> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> <script type="text/javascript" src="ajaxcapturer.js"></script> <script type="text/javascript" src="authenticate.js"></script> </head>
so have been using uiwebview
load page , loading shown in below screenshot.
now if run same thing using wkwebview
page keep on loading shown in below screenshot.
javascript
files firing (added alert) page not load in wkwebview
. below code logic:
-(void)loadwebvw{ wkwebviewconfiguration *config = [[wkwebviewconfiguration alloc] init]; wkpreferences *pref = [[wkpreferences alloc] init]; pref.javascriptenabled = yes; pref.javascriptcanopenwindowsautomatically = yes; config.preferences = pref; cgrect vwframe = cgrectmake(10, 80, 300, 480); wkwebview *webvw = [[wkwebview alloc] initwithframe:vwframe configuration:config]; [self.view addsubview:webvw]; webvw.navigationdelegate = self; webvw.uidelegate = self; nsstring *htmlpath = [[nsbundle mainbundle] pathforresource:@"offline_forms" oftype:@"html"]; nsstring *html = [nsstring stringwithcontentsoffile:htmlpath encoding:nsutf8stringencoding error:nil]; nsurl *baseurl = [nsurl fileurlwithpath: [nsstring stringwithformat:@"%@/javascript", [[nsbundle mainbundle] bundlepath]]]; [webvw loadhtmlstring:html baseurl:baseurl]; //or// // [webvw loadrequest:[nsmutableurlrequest requestwithurl:[nsurl urlwithstring:htmlpath]]]; }
do need add additional stuff load in wkwebview
. please on this. in advance.
Comments
Post a Comment