Disable click in popup

56 views
Skip to first unread message

Karthik Vishwanath

unread,
Jun 16, 2015, 5:27:30 AM6/16/15
to cef...@googlegroups.com
Dear Dmitry:

I have a scenario where all the links, buttons etc on a pop-up (cefwindow) must be disabled/inactive.

Please help me out.

Regards,
Karthik


Lukas Henkel

unread,
Jun 16, 2015, 1:00:22 PM6/16/15
to cef...@googlegroups.com
Either use a separate instance of CefClient with a different CefRequestHandler that overrides the OnBeforeBrowse method and return true, or inject some JavaScript into the popup that adds an event listener to the click event of all links and buttons and just cancel it.
--
You received this message because you are subscribed to the Google Groups "CefGlue" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cefglue+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Karthik Vishwanath

unread,
Jun 17, 2015, 3:06:29 AM6/17/15
to cef...@googlegroups.com
Dear Lukas:

Thanks for the response. Can you please give some examples for both the suggested approach.

Regards,
Karthik K V

Lukas Henkel

unread,
Jun 17, 2015, 2:03:40 PM6/17/15
to cef...@googlegroups.com
I can't give you an example on how to do it directly in CEF, because I do not currently have an environment were I could test it, but here is some JavaScript that will disable all click actions on anchors and buttons:

document.body.addEventListener('click', function(e) {
	if (['A', 'BUTTON'].indexOf(e.target.tagName) !== -1) {
		e.preventDefault();
		e.stopPropagation();
	}
}, true);
This is a very simple way to do it, but there are edge cases were it doesn't work. For example if the anchor contains another element which is actually the one being clicked.
If you actually want to disable all buttons visually, you can do it like that:

Array.prototype.forEach.call(document.querySelectorAll('button'), function(x) {
	x.disabled = true;
});

Links can't be visually disabled without using CSS though.
Reply all
Reply to author
Forward
0 new messages