所有していないサイトに JavaScript を挿入しようとしています。挿入しようとしているコードは次のとおりです。
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
});
});
}
これは動作しません。私が使用している方法はstringByEvaluatingJavaScriptFromString
、ネストされたブラケットなどでは機能しないようです。シンプルなコードで問題なく動作します。
問題は、コードがまったく挿入されていないことです
私の完全なコードは次のとおりです。
[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);"]];
どんな助けでも大歓迎です。ありがとう