Hey guys I'm trying to get the html element that was touched by user in the webview. The scenario is for instance user touches some kind of button in the webview and the application displays the html code for the button like:
I'm already able to get the html code that the user is browsing but problem is with getting the specific html elements.
The websites the user will be browsing through will be a random sites on the internet so I can't simply put an onclick function on the button and notify the android about the click.
Any idea how would I be able to implement that?
try this:
webview.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View view, MotionEvent event) {
WebView.HitTestResult hr = ((WebView)view).getHitTestResult();
Log.i("TAG", "getExtra = "+ hr.getExtra() + "Type= " + hr.getType());
//return true;
return false;
}
});
getExtra() returns the element which is clicked by user and getType() is used to identify which HTML element is clicked by user.
Related
Using Cognos Analtyics 11.1.7IF9.
I have a user who, oddly enough, wants Cognos to make his workflow more efficient. (The nerve!) He thinks that if he can use the TAB button to navigate a prompt page, he'll be faster because he never needs to reach for the mouse.
To test this I created a simple report with a very simple prompt page using only textbox prompts. As I tab I notice it tabs to everything in the browser: browser tabs, the address bar, other objects in Cognos, ...even the labels (text items) I created for the prompts. Oh... and yes, at some point focus lands on a prompt control.
Within Cognos, I see that the tab order generally appears to be from the top down. (I haven't tried multiple columns of prompts in a table yet.) I must tab through the visual elements between the prompts. Also, while value prompts get focus, there is no visible indication of this.
Is there a way to set the tab order for the prompts on a prompt page?
Can I force it to skip the non-prompt elements?
Can the prompts be made to indicate that they have focus?
I tagged this question with javascript because I figure the answer will likely involve a Custom Control or a Page Module.
Of course, then I'll need to figure out how all this will work with cascading prompts and conditional blocks.
I found a similar post complaining about this being a problem in Cognos 8. The answer contains no detail. It just says to go to a non-existent web page.
I had the same frustration as your user and I made a solution a while back that could work for you. It's not the most elegant javascript and I get a weird error in the console but functionally it works so I haven't needed to fix it.
I created a custom control script that does 2 things on a prompt page.
First, it removes the ability to "select" text item elements on the page. If you only have text items and prompts on the page it sets it's "Tabindex" to "-1". This allows you to tab from one prompt field to the next without it selecting invisible elements or text elements between prompts.
Secondly, if you press "Enter" on the keyboard it automatically submits the form. I am pasting the code below which you can save as a .js and call it in a custom control on a prompt page. Set the UI Type to "None"
define( function() {
"use strict";
function AdvancedControl()
{
};
AdvancedControl.prototype.initialize = function( oControlHost, fnDoneInitializing )
{
function enterSubmit (e)
{
if(e.keyCode === 13)
{
try {oControlHost.finish();} catch {}
}
};
function setTab () {
let nL = [...document.querySelectorAll("[specname=textItem]")]
//console.log(nL)
nL.forEach((node) =>{
node.setAttribute('tabindex','-1')
})
};
setTab();
let exec_submit = document.addEventListener("keydown", enterSubmit, false);
try {exec_submit;} catch {}
fnDoneInitializing();
};
return AdvancedControl;
});
I have searched a lot of information about this but have not found the solution yet.
My problem is the following, I am creating an extension to speed up the movement through several web pages, I have managed it with many of them, but I have come to some where I cannot simulate a click with Javascript and I don't know how to do it.
One of the pages is this: https://sports.betway.es/es/sports/in-play The page is in Spanish domain, therefore I do not know if they can access it from another country (without vpn), although I think that with domain ".com" it works.
The code is as follows, it's pretty simple.
var deportesActivos = document.getElementsByClassName("categoryListItemWrapper contentSelectorItemButton")
for(let i=0;i<deportesActivos.length;i++){
let nombre = deportesActivos[i].lastChild.firstChild.innerText
if(nombre == data.deporte){
deportesActivos[i].click()
}
}
deportesActivos I collect the DIV elements with that class from the page.
deportesActivos[i].lastChild.firstChild.innerText I extract the text of each element
if(nombre == data.deporte){
deportesActivos[i].click()
}
When it matches, click to enter the link.
The problem is that the click does not simulate me.
I have bought exactly the element that you click on, I have clicked manually and it works, I have tried to click on other elements of the web page and it does not work, I have tried to give a "listener on click" to the element and it does not work either.
The HTML of the page is as follows:Image with HTML Code of the website
I don't know if this helps but on website build with Ionic app neither works
The click event does not fully simulate a user click. It just fires the onClick handler on the element that you are targeting (and any parents).
If your are just redirecting to a new URL when the button is clicked, you could just do that in your loop instead.
// get the links, not the buttons
var deportesActivos = document.getElementsByClassName("categoryListItemWrapper contentSelector");
for (let i=0; i < deportesActivos.length; i++) {
// Drill down one extralevel to get the button text
let nombre = deportesActivos[i].firstChild.lastChild.firstChild.innerText;
if (nombre === data.deporte) {
// Redirect to the href in the link
window.location.href = deportesActivos[i].href;
}
}
I want to catch and consume (prevent redirection) link events on the teamdev's jxbrowser. Suppose the content is
link
When the user clicks the link, I want to be informed that the user has clicked the link and get the URL, but I do not allow the page change (link should be consumed).
The problem is, the links in the quotes of the anchor tag do not start with any protocol (http:// or https:// and do not end with any .html or etc). For example the link is in the form of:
<a href="foo">link<a>
and we want when user clicks on the link, we get informed that the clicked string is foo. I know, the links in this a tag are not valid and not well formed due to the standarts, but the contents are generated by using some specific busines rules and then set to the JxBrowser. And we can not change the way the links are created.
With the example below, we get about:blank for the url, which is not the desired info. If we change to
link
then it works fine but we can not modify the links (content) as I have mentioned before.
browser.addLoadListener(new LoadListener () {
public void onStartLoadingFrame(StartLoadingEvent arg0) {
System.out.println("link click occured " + arg0.getValidatedURL());
arg0.getBrowser().stop();
}
);
LoadHandler allows you to handle any activity related to loading. Using LoadHandler you can determine the load type and cancel any load events. Here is an example:
browser.setLoadHandler(new DefaultLoadHandler() {
#Override
public boolean onLoad(LoadParams params) {
if (params.getType() == LoadType.LinkClicked) {
System.out.println("Link clicked: " + params.getURL());
return true;
}
return false;
}
});
I am using the Qt Web Kit 1.0 to open web pages. I have a keyboard available with me, written in qml. I want to use this keyboard to fill in the text into text boxes of the HTML pages.
Say, I opened gmail.com. Now, I want to fill in the user name and password. But when I will click on this text element of the webpage, what event should I handle to bring out my keyboard for user to use it ? And where exactly will I send this text generated from the keyboard, for it to be set into the username field of that page ?
You can change the text field value by evaluating some custom javascript code in the WebView:
webViewId.evaluateJavaScript("document.getElementById('textInputId').value = '" + yourValueString + "'")
Documentation here.
Edit:
For the keyboard activation you can refer to the javaScriptWindowObjects property: you can activate it, for example, in the body onload event, or in the text field onfocus event.
Edit2:
I add a simple example to explain what I'm trying to say:
I assume you have a QML custom Item called Keyboard, and that this Item has a signal onKeyPress called whenever a key is pressed.
Your code should be something like this:
WebView {
id: webViewId
javaScriptWindowObjects: QtObject {
WebView.windowObjectName: "qml"
function showKeyboard {
keyboardId.opacity = 1;
}
}
onLoadFinished: {
evaluateJavaScript("document.getElementById('textInputId').onfocus = window.qml.showKeyboard;")
}
}
Keyboard {
id: keyboardId
opacity: 0
onKeyPress: {
webViewId.evaluateJavaScript("document.getElementById('textInputId').value += '" + keyValue + "'")
}
}
Here's what I"m trying to do. I have a hyperlink like this on my page:
Whatever Page Here
When a user clicks the link I want to grab that click. If it's a link I don't want them to click (like something that doesn't match the format http://www.wikipedia.com/wiki/xxxxx) I want to pop a message box. Otherwise I want to funnel them through my Mvc Controller instead. like this:
//Category is the "Whatever_Page_Here" portion of the Url that was clicked.
public ActionResult ContinuePuzzle(string category)
{
}
Any suggestions?
Start by intercepting all the click events:
$(function() {
$("a").click(ClickInterceptor);
});
function ClickInterceptor(e)
{
// code to display popup or direct to a different page
if (redirect)
{
var href = $(this).attr("href").split("/");
location.href = "http://mydomain.com/controller/" + href[href.length - 1];
}
return false;
}
The "return false;" tells the anchor not to fire the navigate.
If you want to select all the a tags which do not start with "http://http://www.wikipedia.com/wiki/" you would use:
$("a").not("a[href^='http://http://www.wikipedia.com/wiki/']")