コード例 #1
0
        void listen_clicks()
        {
            MainWindow.This.Browser.ExecuteJavaScript(
                CefSharpBrowser.Define__getElementsByXPath()
                + CefSharpBrowser.Define__createXPathForElement() + @"
if(document.__onElementSelected){
    document.__clickedElement = null;
    return;
}
document.__onElementSelected = function(event){
    try{
        if ( event.preventDefault ) event.preventDefault();
        if ( event.stopPropagation ) event.stopPropagation();
        event.returnValue = false;
        var target = event.target || event.srcElement;
        if(document.__clickedElement == target)
            document.__selectedElement = document.__selectedElement.parentNode;
        else
            document.__selectedElement = target;
        document.__clickedElement = target;
        var x = document.__createXPathForElement(document.__selectedElement);
        window.JsMapObject.htmlElementSelected(x);
    }catch(err){
        alert(err.message);
    }
    return false;
};

document.addEventListener('contextmenu', document.__onElementSelected, false);
     
");
        }
コード例 #2
0
            List <string> get_single_element_xpaths(string xpath)
            {
                var os = (List <object>)MainWindow.This.Browser.ExecuteJavaScript(
                    CefSharpBrowser.Define__getElementsByXPath() +
                    CefSharpBrowser.Define__createXPathForElement() + @"
var es =  document.__getElementsByXPath('" + xpath + @"');
var xs = [];
for(var i = 0; i < es.length; i++){
    xs.push(document.__createXPathForElement(es[i]));
}
return xs;
            ");

                List <string> xs = new List <string>();

                if (os != null)
                {
                    for (int i = 0; i < os.Count; i++)
                    {
                        xs.Add((string)os[i]);
                    }
                }
                return(xs);
            }