UIWebView JavaScript Injection

I've been browsing through enough blogs, so I'm sure this is encoded ... but none of them seem to mention where the javascript injection goes into Obj-C code? Basically, all I want to do is get rid of the title on all the pages that the user can go to (or at least the initial page load ... I will worry about subsequent pages later if this is a problem. Stupid) . Here is the code I have:

[self stringByEvaluatingJavaScriptFromString: @ "document. getElementById ('login'). childNodes [1] .innerHTML = ''"];

I just damn find a place where he should work. I mainly attribute this to the fact that I do not quite understand UIWebView. I thought that I would post it here, and then at the same time read how it works, and maybe think about it on my own.

+1
source share
1 answer

Your javascript code must be executed with one loaded HTML document (and all of its DOM objects).

Thus, you must insert your call to stringByEvaluatingJavascriptFromString in the UIWebView delegate method - (void)webViewDidFinishLoad:(UIWebView *)webView (of course, you need to implement this code in an object that will be set as a UIWebView delegate, as for any delegate method, and for every time you use the delegate template)

+1
source

Source: https://habr.com/ru/post/1402990/


All Articles