1

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.

Cezar
  • 55,636
  • 19
  • 86
  • 87
  • 1
    By executing JavaScript on the page from UIWebView after it loads. [See this answer](http://stackoverflow.com/a/8886806/2089625) – Ric Feb 23 '13 at 03:16

2 Answers2

4

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'"];
}
Cezar
  • 55,636
  • 19
  • 86
  • 87
0

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)
Vivek Bansal
  • 1,301
  • 13
  • 21