I'm trying to create a Chrome Extension that deals with selected text. Some website pages' otherwise selectable text content has click/mouse-up/down event handlers that navigate to a new page.
Is there a way from the background or content script to temporarily disable (and restore) the page's arbitrary event handlers without interfering with the native text selection?
Worst case I'm thinking of is to detach, clone the body html, allow the selection, and then restore the bound original. Seems like trouble.
Thanks!
Most HTML DOM events follow the capture-target-bubble event model. This means, for example, that if you click on a button, that the "click" event is first dispatched at the root, all the way down to the button, then back up. Event propagation can be stopped, which prevents the event listener at the next level from being notified of the event.
The earliest possibility of receiving the event is at the root, often window at the capture phase. To bind an event listener to the capture phase, use addEventListener with the third parameter set to true:
// in a content script, at run_at:document_start
window.addEventListener('click', function(event) {
event.stopImmediatePropagation();
}, true);
Many web pages use jQuery to manage DOM events, which binds the event listeners at the bubbling phase, so the previous method will work on most sites. If the page does not use jQuery, then you have to bind your event listener at document_start to make sure that your event listener is triggered before every other event listener.
Related
I have a custom module that contains a button. The button click performs a process that sometimes takes 5-10 seconds to complete. Is there a way in Kentico to display a custom busy message like the "Loading" message that Kentico displays during lengthy processes? I would like to show the same "Loading" msg that Kentico shows with my own custom message.
If your module is built using the out of the box page templates and webparts, this is included by default. If it is not and you're using custom aspx template pages, you'll need to ensure that the page in inherited properly and add that in. You might want to reference another out of the box module which is using code already like the Users in the Membership module.
Yes, but it depends on how things are set up.
If the button executes an Ajax Panel (it does a postback through an ajax call), then you can capture the ajax call and put your loading message there.
<script type="text/javascript>
var AjaxHandler = Sys.WebForms.PageRequestManager.getInstance();
AjaxHandler.add_beginRequest(beginRequestHandler);
AjaxHandler.add_endRequest(endRequestHandler);
function beginRequestHandler(sender, args) {
// Waiting
}
function endRequestHandler(sender, args) {
// close waiting
}
</script>
If you have it postbacking on the page, you can try to put a hook when the button is clicked to show the waiting, when the page refreshes then the waiting will of course be gone.
$("#mybutton").click(function() {
// Waiting
});
I have an issue with designing my application.
On my login form, I fire off an event in my ViewModel that's handled in the View (it displays a progress bar).
Then I query the database
Based on the query result I fire off an event from my ViewModel whose handler displays a message based on the result
The problem is when the query executes so fast that the (async) event handler doesn't even get to initialize the progress bar before the second event gets fired. The second event handler registers that there are no progress dialogues open so it doesn't try to close the open one before displaying the message. And when the user acknowledges the message, he is left with a indeterminate progress dialog which blocks the rest of the UI.
What design pattern should I utilize to avoid this race condition?
I think the title says it all. Suppose I have an extension X which has event listeners for some event(s). Is it possible for another extension, say Y, to get the list of all those event listeners ?
you can get the list of event listeners on a specific element, as explained by this post:
How to find event listeners on a DOM node?
But Chrome extensions are made to be invisible, the page cannot detect that an extension inserted a content script inside of it. Extensions are basically closed off, and no other page, or extension, can catch a glimpse of what goes on within another extension's content scripts. So You can try, but i severely doubt it to be possible.
when I open an XPage with a lot of ssjs in it. I have always the problem, that when I click a button (with ssjs in it) directly after opening the page, nothing happens. When I wait 1 or 2 seconds, every thing works as expected. It seems, that not everything is loaded fast enough.
Is there an event to see if the document is completly loaded? I tried the jquery and dojo onready events and as well the onClientLoad event. But all these events trigert directly after the page is open (but not finish loaded).
You can add the following onClientLoad event as a client side javascript:
XSP.addOnLoad(new function() {
// this will run when everything is ready...
});
That's also why you see a lag for button events. All event handlers are binded via the same mechanism as above.
It was my fault. I just recognized that there are more than 30 panels there all have an empty onClientLoad method in it. After I removed the events, my page need to load 500ms insted of 2,5s and also the XSP.addOnLoad event to see if the page is ready now works as expected.
Thanks #Serdar Basegmez for your help.
I have a bunch of control objects (TextBoxes, to be precise) that get injected into my code using the #FXML annotation during the FXML load.
I would like to save the states of these controls, specifically the text values, when the user closes the Scene by clicking the close box on the title bar.
However, when I trap the CloseRequest event in an OnCloseRequest handler I find that the values of the control variables are null (the original injection works, so this is something that happens in between the loading of the FXML and the calling of OnCloseRequest).
Can anyone explain this behavior and/or suggest how I can get the functionality that I want?
TIA
onCloseRequest is
Called when there is an external request to close this Window. ...
(from Javadoc). One of the meanings of "external request" is when you close the window through OS native window close button. The closeRequest event is not triggered through the programmatic stage.close() or stage.hide() calls. So consider to handle onHiding or onHidden events.
Otherwise post your OnCloseRequest handler code.