Welcome Guest Search | Active Topics | Sign In | Register

Javascript injection Options
ac2015
Posted: Thursday, December 24, 2015 5:36:06 AM
Rank: Member
Groups: Member

Joined: 12/24/2015
Posts: 14
Hello!

I would like to set the focus to the first text input element.

I am using this code:

Quote:
'and the following Javascript-injection ensures, that the first
'found input-element (if there is one) will be focused
i = i + 1 : JS(i) = "<script>"
i = i + 1 : JS(i) = "var inputElements = document.getElementsByTagName('input');"
i = i + 1 : JS(i) = "for(i=0; i<inputElements.length; i++)"
i = i + 1 : JS(i) = "{"
i = i + 1 : JS(i) = " if (inputElements[i].type != 'hidden')"
i = i + 1 : JS(i) = " {"
i = i + 1 : JS(i) = " if (inputElements[i].disabled == false)"
i = i + 1 : JS(i) = " {"
i = i + 1 : JS(i) = " inputElements[i].focus();"
i = i + 1 : JS(i) = " inputElements[i].scrollIntoView(true);"
i = i + 1 : JS(i) = " break;"
i = i + 1 : JS(i) = " }"
i = i + 1 : JS(i) = " }"
i = i + 1 : JS(i) = "}"
i = i + 1 : JS(i) = "</script>"

_Browser.WebView.EvalScript(Join(JS))


However, nothing happens.

Can anybody tell me what I am doing wrong?
I think my javascript code is correct, so I think "EvalScript" is perhaps not the right method.

Thank you for the help.
eo_support
Posted: Thursday, December 24, 2015 3:02:17 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Hi,

You should not include script tag in the value you passed to EvalScript. For example, EvalScript("alert('hi')") is valid, but EvalScript("<script>alert('hi')</script>") is invalid.

Thanks!
ac2015
Posted: Thursday, December 24, 2015 4:48:19 PM
Rank: Member
Groups: Member

Joined: 12/24/2015
Posts: 14
Thank you, I will try that.


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.