Question

I have a UIWebView in which I load a NSURLRequest. I do not have full control over the html for the page shown but I do know it will contain an element which has an id I happen to know beforehand. Let's say it is submmit_form_button.

I don't want the user of the app to see this element. I want to hide it before it appears to the user in the UIWebView.

What is the best option to do that? Where in the controller that shows the UIWebView should I put the code that will solve this? I am aware that I can use Javascript for this. I am more concerned about how can I approach this in the context of a native iOS app that shows a UIWebView which gets it's html from an external source.

Was it helpful?

Solution

Following the lead from the comment by @Ric I solved the problem with

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    [webView stringByEvaluatingJavaScriptFromString:@"document.getElementById('submmit_form_button').style.display = 'none'"];
}

OTHER TIPS

In order to hide multiple items in same separate line with ";".

Here is example in Swift:-

let items = "document.getElementById('item_1').style.display='none';" 
            + "document.getElementById('item_2').style.display='none'"

webView.stringByEvaluatingJavaScript(from: items)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top