0
HTML代碼的鏈接在Android上工作:的JavaScript。點擊()方法不是在某些情況下
<a href="#" id="10" target="_blank">
some codes here...
</a>
代碼中,我CALL我的應用程序:
webView.loadUrl("javascript:(function(){document.getElementById('10').click();})()");
,但沒有結果...
我已經啓用JavaScript的我的webView之前,它的工作原理... 並且我測試了其他網頁上的其他元素的.click()方法,它能正常工作。
我該怎麼做才能讓webView點擊鏈接...?請幫幫我;謝謝 !
EDIT :
Perhaps it's because of the numeric start of id name of these elements,
but I can use them using their id or tag name on
google chrome console on windows without any problem...
but It's not possible to use them using their tag name, even, to click on, on android webView !
EDIT 2 :
The problem isn't numeric start of 'id's in fact !
I've found out that click function doesn't work even for other ids without numerics
IN THIS PAGE I'M USING ONLY...
AND THIS IS WHAT I CAN'T UNDERSTAND WHY !!!
I've tried creating fireEvent function, too... FAIL AGAIN !
I SHOULD ADD THAT THE HTML CODE OF THE PAGE IS SOMETHING LIKE THIS IN FACT :
<div class="abc"><a href="#" id="defg"></a></div>
EDIT 3 : Sorry I forgot to say that these elements should open a window in the page
when they are called by click.
I found out that when I click them using javascript on android,
the html source of the page changes (so the Click is being called as we need)
, but the window doesn't open and it's data are not received...
EDIT 4 : I have used these codes after defining my webView, so what's the problem exactly ???
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webView.setWebViewClient(client);
webView.setWebChromeClient(new WebChromeClient());
webView.addJavascriptInterface(iface, "droid");
謝謝,但是沒有其他辦法嗎? ,因爲它可以在windows上的谷歌瀏覽器控制檯上使用這些元素,例如... –
也可以使用html5中的'data-'元素來引用某個元素。 – obey
你能幫我多...嗎? 我該如何在android上使用它來點擊webview中的這個元素? –