Web页面检查器模式中的JavaFX和Firebug Lite [英] JavaFX and Firebug Lite in web page inspector mode

查看:186
本文介绍了Web页面检查器模式中的JavaFX和Firebug Lite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 WebView 创建了一个使用JavaFX的简单浏览器。我还添加了Firebug Lite来检查网站。为了启用Firebug Lite,我使用了 WebEngine 和方法 executeScript()

I created a simple browser with JavaFX using WebView. I have also added Firebug Lite to inspect the website. To enable Firebug Lite I used a WebEngine and the method executeScript():

engine.executeScript("if (!document.getElementById('FirebugLite')){E = document['createElement' + 'NS'] && document.documentElement.namespaceURI;E = E ? document['createElement' + 'NS'](E, 'script') : document['createElement']('script');E['setAttribute']('id', 'FirebugLite');E['setAttribute']('src', 'https://getfirebug.com/' + 'firebug-lite.js' + '#startOpened');E['setAttribute']('FirebugLite', '4');(document['getElementsByTagName']('head')[0] || document['getElementsByTagName']('body')[0]).appendChild(E);E = new Image;E['setAttribute']('src', 'https://getfirebug.com/' + '#startOpened');}");

如何拦截Firebug Lite检查员功能的返回值(我猜的字符串) JavaFX?

How can I intercept the return value (a string I suppose) of the function of Firebug Lite's inspector in JavaFX?

推荐答案

我对JavaFX没有任何经验,但我知道Firebug Lite没有公开您检查过的元素用它也不会触发任何与之相关的事件。因此,您无法直接访问该信息。请参阅相关源代码

I don't have any experience with JavaFX, though I know that Firebug Lite does not expose the element you inspected with it nor does it trigger any events related to that by itself. So you can't access that information directly. See the related source code.

Firebug Lite基本上做的是创建< div> 作为荧光笔的叠加层为 mousemove mousedown 设置两个事件处理程序,以便它处理鼠标点击,您也可以听取您的目的。

What Firebug Lite basically does is to create a <div> as overlay for the highlighter and to set two event handlers for mousemove and mousedown for it to process the mouse clicks, which you can also listen to for your purposes.

要通过JavaScript通过Firebug Lite检查元素,您可以使用以下代码:

To get the element inspected via Firebug Lite via JavaScript you can use this code:

document.addEventListener("mousedown", function(e) {
  if (e.target.id === "fbInspectFrame") {
    var inspectedElement = Firebug.browser.getElementFromPoint(e.clientX, e.clientY);

    // Here goes the code, which processes the inspected element
  }
});

说明:

要获取被检查元素,您必须收听 mousedown 事件。但是只有在启用检查器时才会发生这种情况,当被检查元素实际上是覆盖< div> 时,调用时会注入fbInspectFrameFirebug Lite。

To get the inspected element, you have to listen to the mousedown event. But the action should only happen when the inspector is enabled, which is true when the inspected element is actually the overlay <div> called 'fbInspectFrame' Firebug Lite injects while inspecting.

获取实际检查的元素(注意它是一个对象,而不是一个字符串)Firebug Lite提供了一个名为的函数Firebug.browser.getElementFromPoint( ),使用事件中的鼠标坐标调用。

To get the actual inspected element (note that it's an object, not a string) Firebug Lite offers a function called Firebug.browser.getElementFromPoint(), which is called with the mouse coordinates from the event.

然后,您的JavaFX代码需要访问此JavaScript元素。

This JavaScript element then needs to be accessed by your JavaFX code.

这篇关于Web页面检查器模式中的JavaFX和Firebug Lite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆