anyone tell me how to get div id from a script webview i used this code but this is not working
NSString *strTitle1=[webView stringByEvaluatingJavaScriptFromString:#"document.getElementById('div_indicator').innerHTML;"];
NSLog(#"strtil:%#",strTitle1);
Try this code Objective-C-HMTL-Parser
and this hpple
and you have this tutorial How to parse html on iOS
Related
I am trying to add an image of a map generated by the google map static api in my Nativescript application (I'm using Nativescript with Vue).
I am able to make it work on Android but I have some issues on iOS.
I simply have an Image component like that <Image :src="map_source" />
And in my vue data, I have map_source: "https://maps.googleapis.com/maps/api/staticmap?&markers=48.2,2.1&path=color:red|weight:5|fillcolor:red|48.2,2.1|48.3,2.13|48.4,2.12&zoom=10&size=460x200&key=MY_API_KEY"
When I use this URL in my browser, I get the desired map.
When I use this URL in my app on Android, it displays the map correctly.
But when I use the same URL in my app on an iOS device, the map is not displayed at all.
Note: if I remove the path (e.g map_source: "https://maps.googleapis.com/maps/api/staticmap?&markers=48.2,2.1&zoom=10&size=460x200&key=MY_API_KEY", the image is correctly displayed on both Android and iOS. The error only appens when I add the path.
Is this an iOS issue or am I doing something wrong ?
I was able to find the issue thanks to #Manoj. On iOS devices, the URL was unsupported because of the "|" character. So I had to encode it like so:
let imageSourceModule = require("tns-core-modules/image-source");
let url = encodeURI("https://maps.googleapis.com/maps/api/staticmap?&markers=48.2,2.1&zoom=10&size=460x200&key=MY_API_KEY")
imageSourceModule.fromUrl(url).then(res => {
this.map_source = res;
});
I am working on a hybrid HTML5/iOS app that uses the Safari Webview. We are using AirPrint to allow the user print the contents of the webview. The problem I am having is that after the print dialog is opened, the print styles are taking affect on the screen, and even after printing is complete or canceled do not go away. This does not happen in our Windows or Android versions of the app, which use CEF and Android System Webview respectively. Print styles in those versions of the application are only applied to the print out, as expected.
Anyone have any experience using AirPrint with Safari Webview that could shed some light on a solution? I have considered just adding/removing the link tag containing the CSS with javascript before and after printing, but that feels hacky, and doesn't answer the curious question of why print styles are being applied to the screen.
Any help appreciated! Sorry there is no real way to attach code to this!
Yes, this is indeed a not expected behaviour. However, we can try to solve this using JavaScript.
Theory: When the print is done, let's reload the stylesheets. The browser will paint the page again and hopefully using screen definitions.
Practice: As we don't have a JavaScript callback after printing, you could try reload your stylesheets using the window.onfocus event, as follows:
function updateStylesheets(){
var links = document.getElementsByTagName("link");
for (var x in links) {
var link = links[x];
if (link.getAttribute("type").indexOf("css") > -1) {
link.href = link.href + "?id=" + new Date().getMilliseconds();
}
}
}
window.onfocus = updateStylesheets;
In detail, it grabs all <link> tags and appends a random number after, forcing a reload on the stylesheets.
Please let me know if that worked, I'd be glad to help.
My question is: Can UIWebView import from website only plain text? Without any formatting etc? Or mayby there is another simple way to import just simple text from website into an iOS app?
Thanks for help!
It shouldn't be done with UIWebView.
Use an Http Connection to get page content then strip the HTML tags.
nsurlConnection
Stripping
or, in the did finish loading get html and strip it then reset the webview content
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[myUIWebView loadHTMLString:strripedString baseURL:nil];
}
I have followed this tutorial http://www.raywenderlich.com/2636/how-to-make-a-simple-rss-reader-iphone-app-tutorial#comments
But I also want to get description/content instead of showing its URL in web view.
I tried everything but nothing worked.
Any help?
As shown in ray wenderlich website, you can get the feed details from GDataXML's GDataXMLElement. Check the key you are getting for description/content GDataXMLElement like:
[item valueForChild:#"description"]
and save that string in the nsobject class you created to save the rss feed required data. After that you can load html string in the webview and add your custom css styling for the html string if needed. You can load html string in webview using webview's
- (void)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL
method. Hope my answer helps.
Is there any way to refresh only part of an HTML file displayed in a UIWebView? For example, if I make changes to a div in the body, is there any way to refresh only the contents of that div tag? Or do I have to reload the entire file into my UIWebView?
You have to reload entire HTML file. It is not possible to reload only part of pure HTML file.
Using a little bit of javascript?
use javascript like this
NSString *js = [NSString stringWithFormat:#"document.getElementById('foo').innerHTML ='update';"];
NSString *res = [self stringByEvaluatingJavaScriptFromString:js];