Firefox OnClick事件无效



我正在尝试调试第三方脚本。

它在Chrome中正常工作。但是Firefox不会注册OnClick事件。

知道为什么Firefox不会玩得不错?

我尝试在此处建议添加return false;,但它不起作用,并在最后一个闭合括号上方添加时,在控制台中查看时会产生更多的错误。

	function ac_event(event, eventdata) {
    
    return ajax({
        url: activecampaignevent.ajax_url,
		type: 'POST',
        data: {
			action: 'ac_event',
			event: event,
            eventdata: eventdata
		},
		success: function (response) {
			console.log('response', response);
		}
    });
    
    function ajax(options) {
        var request = new XMLHttpRequest();
        var url = options.url;
        var data = encodeData(options.data);
        
        if (options.type === 'GET') {
            url = url + (data.length ? '?' + data : '');
        }
        request.open(options.type, options.url, true);
        request.onreadystatechange = onreadystatechange;
        
        if (options.type === 'POST') {
            request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
            request.send(data);
        } else {
            request.send(null);
        }
        return;
        
        function onreadystatechange() {
            if (request.readyState === 4 && request.status === 200){
                options.success(request.responseText);
            }
        }
        function encodeData(data) {
            var query = [];
            for (var key in data) {
                var field = encodeURIComponent(key) + '=' + encodeURIComponent(data[key]);
                query.push(field);
            }
            return query.join('&');
        }
    }
}
<a href="https://somelink.com/" onclick="ac_event('Link Clicked', 'Some Link');">Click this link to test</a>

您可以在JavaScript中创建事件并使用浏览器事件分配以停止使用DestrestDefault。

document.querySelector("#LinkID").addEventListener("click", function(event){
          //do your code here
            alert("preventDefault will stop you to go")
            event.preventDefault();
        }, false);

最新更新