I am saving the content of UIWebView
so as to display it on the next launch rather than again loading it. This is what I am doing:
NSString *activityesContent = [webView stringByEvaluatingJavaScriptFromString:@"document.body.outerHTML"];
[[NSUserDefaults standardUserDefaults]setObject:activityesContent forKey:@"activityesContent"];
And for the next launch I am doing this:
[_tgWebView loadHTMLString:[[NSUserDefaults standardUserDefaults]objectForKey:@"activityesContent"] baseURL:nil];
This loads the page but without any JavaScript or CSS. It is just a basic HTML content. I know I can load the JavaScript using stringByEvaluatingJavaScriptFromString. But is there somehow I can get all the JavaScript and CSS on the page as I am getting the HTML content, so that I can use it later on?
I also tried with document.body.parentNode.innerHTML
and document.documentElement.outerHTML
, but still basic HTML is displayed. The reason for this is, the images, CSS and JavaScript has a server path. I have asked one more question but it doesn't work for my HTTPS requests.
Neither does this work:
NSError *error = nil;
NSString *activitiesContent = [NSString stringWithContentsOfURL:[NSURL URLWithString:TGURL_ACTIVITIES] encoding:NSUTF8StringEncoding error:&error];
I tried this solution which is being referred at most of the places. But this gives me a blank page. I even tried to save the contents in a file. When I accessed the source of the page in the file, I found that the path of CSS and JavaScript is relative:
<link href="/Content/Sass/style_sass.css?version=1.0.1.09" rel="stylesheet" /> <!-- call style_sass.css file -->
<link href="/Content/Sass/topbar.css?version=1.0.1.09" rel="stylesheet" />
If I try creating resource folder, the size of this folder will be huge. Plus there will be a maintenance issue. I have to update the CSS/JavaScript each time there is a change in server CSS/JavaScript.
This is what I am getting:
And this is what the page should be:
Finally what I want:
What is the best fix for this or is there some other way I can show the entire page (including CSS, JavaScript, images) on the app's further launches ?