I am trying to inject some javascript into a site I do not own. The code I am trying to inject is as follows:
function submitFormForTime(time){
$(".t_h").each(function(i, obj){ // find each element with the class t_h
if ($(this).text() != time) return; // not the right one
$(this).parent().find("form").each(function(i, obj){
obj.submit(); // submit that form
});
});
}
This does not work. It seems that the method I am using, stringByEvaluatingJavaScriptFromString, does not work with nested brackets or whatever. It works fine with simple code.
The problem is that the code is not being injected at all
My full code is as follows:
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:
@var script = document.createElement('script');
"script.type = 'text/javascript';"
"script.text = \"function submitFormForTime(time){ "
"$(\".t_h\").each(function(i, obj){"
"if ($(this).text() != time) return;"
"$(this).parent().find(\"form\").each(function(i, obj){"
"obj.submit();"
"});"
"});"
"}\";"
"document.getElementsByTagName('head')[0].appendChild(script);"]];
Any help would be greatly appreciated. Thanks