如何禁用超链接和提交表单的所有操作,但可以拖动这些元素

时间:2014-10-16 04:50:38

标签: html css javafx javafx-webengine

我使用JavaFx WebView来显示网页,但我不想在网页上进行任何交互(位置更改)以及禁用Javascript的Web引擎。由于这个原因,我尝试禁用超链接的所有操作并通过

提交表单
a[style] {
    pointer-events: none !important;
    cursor: default;
}

input[style] {
    pointer-events: none !important;
    cursor: default;
}

所以我无法拖动它们。有这个问题的另一种方法?通过CSS或JavaFx解决它更好。
谢谢你的进步。

2 个答案:

答案 0 :(得分:1)

使用Jquery:

$('input[type="submit"]').attr('disabled','disabled');

$('a').attr('disabled','disabled');

喜欢this

答案 1 :(得分:1)

您可以尝试阻止对任意数量的事件执行默认操作。请注意,浏览器通常允许这样做,但确实有最后的发言权(我记得有些问题并不总是有效)。

var events = ["keypress","click","submit","focus","blur","tab"];
events.forEach(function(eventName){
    window.addEventListener(eventName, function(e){
        // this is the list of tags we'd like to prevent events on
        // you may wish to remove this early return altogether, as even a div or span
        // can cause a form to submit with JavaScript
        if (["INPUT","A","FORM","BUTTON"].indexOf(e.tagName) === -1) {
            return;
        }

        // prevent the default action
        e.preventDefault();

        // stop other JavaScript listeners from firing
        e.stopPropagation();
        e.stopImediatePropagation();

        // if an input is somehow focused, unfocus it
        var target = e.target;
        setTimeout(function(){
          if (target.blur) target.blur();
        }, 50);
    // true as the third parameter signifies 'use capture' where available;
    // this means we get the event as it's going down, before it starts to bubble up
    // our propagation prevention will thus also prevent most delegated event handlers
    }, true);
});

你无法用CSS解决这个问题。 pointer-events不允许您指定哪些指针事件可以。为此,你需要JavaScript。