私は注入されたjavascriptを使ってwebviewでいくつかのアクションを実行するiOSアプリケーションで作業しています。私はルータのWebインターフェイス上の送信ボタンを押してしようとしています(私はあなたにURLを与えることはできません)。私は他の多くの提案されたソリューションをオンラインで試みましたが、何も機能していません。私がしなければならないことの1つは、タイプ= SUBMITの入力ボタンをクリックすることです。何らかの理由で応答しません。私はonClickイベントハンドラを呼び出すと一緒に.click()を使用しようとしましたが、何も動作していません。どんな助けもありがとうございます。 HTMLコードは以下の通りです:JavascriptとWebViewでHTML入力ボタンをクリックできません(おそらくiframeの問題、わからない)
<div class="fix_button">
<table width="100%" border="0" cellpadding="0" cellspacing="2">
<tbody>
<tr>
<td nowrap="" colspan="2" align="center">
<input class="cancel_bt" type="RESET" name="Cancel" value="Cancel" onclick="doCancel();" languagecode="51">
<input class="apply_bt" type="SUBMIT" name="Apply" value="Apply" onclick="return checkData();" languagecode="50">
</td>
</tr>
</tbody>
</table>
</div>
入力ボタンがclass="apply_bt"
を有するものです。このdivはiframe内にあり、このフレーム内の別のiframe内にあるデータを送信します。構造は次のようにソートのです:
// Gets the outer iframe
iframe1 = document.getElementById("formframe");
// Gets the html within the iframe
var innerDoc=iframe1.contentDocument || iframe1.contentWindow.document;
// Gets iframe within the iframe
innerframe = innerDoc.getElementById("2g_setting");
// Gets the html within the inner iframe
var innerDoc2=innerframe.contentDocument || innerframe.contentWindow.document;
// I Enter some data in the inner iframe (not shown), this portion
// of the code works perfectly. I can see fields being entered and
// buttons being clicked.
// Then I click the apply button...
innerDoc.getElementsByName("Apply")[0].click()
// And nothing happens
私は、このような、要素を取得し、[適用]ボタンからデータを読み取ることができています:
<iframe>
// Contains the Apply Button
<div class="fix_button"></div>
// Contains the iframe where the info to be submitted is
<div id="main" class="main_top_button">
// Contains data to be submitted
<iframe src="WLG_2g_wireless2.htm&todo=wifi_primary_init" id="2g_setting" name="wl2gsetting" onload="SetCwinHeight(this.id)" marginheight="0" marginwidth="0" scrolling="no" width="100%" frameborder="0" height="288px">
</iframe>
</div>
</iframe>
これは私がボタンをクリックして使用していたコードですボタンとして.click()アクションを実行することはできません。また、私は何の誤りもありません。私はなぜそれが動作しているのか分かりません。助けてください!
クイックアンサーに感謝します。あなたのコードを試しましたが、残念ながらそのコードは動作しませんでした。ボタンはまだクリックされません。まだエラーは表示されません。内部フレームにデータを入力する前のコードはうまく動作しますが、イベントはまだ発生しません。どんな考え?他の解決策はありますか? – metacore