It is that UIWebview and toggle button on UIView.
WebPage includes javascript.
I want to control UIWebView’s javascript.
What I want is that whenever Button on UIView is toggled, javascript is turned on or off.
Is it possible?
If so, how can i do? It is sad that I don’t have idea.
This is my javascript code:
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *var = nil;
var = @"<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>"
"<html> "
" <head> "
" <title> New Document </title> "
"<script type='text/javascript'> "
"function colorChange(){ "
" var id=document.getElementById('yellow'); "
" var backcolor = id.style.backgroundColor; "
" "
" if (backcolor != '') "
" { "
" id.style.backgroundColor = ''; "
" }else{ "
" id.style.backgroundColor = '#ffff00'; "
" } "
" "
"} "
"</script> "
" </head> "
" <body> "
"<script type='text/javascript'> "
"</script> "
" "
"<span id='yellow' ><a href=\"javascript:void(0)\" onclick='colorChange();'><font size=12>text</font></a></span></head></html>";
[self.webView loadHTMLString:var baseURL:nil];
}
Don’t think it’s possible to disable JavaScript for a UIWebView.
But you can use the
stringByEvaluatingJavaScriptFromString:method of UIWebView, in order to execute specific JS code, all a JS function, etc.For instance:
If you want to deactivate the
onclick()you’ve set, you can for instance set a global variable withstringByEvaluatingJavaScriptFromString:, and check for that variable in yourcolorChangefunction. If it has some value, do something, otherwise, do nothing.And so: