Thursday, 12 September 2013

How can I replace window.confirm with custom code?

How can I replace window.confirm with custom code?

For accessibility reasons, for my Chrome extension, I need to be able to
replace all standard window.confirm popups with an in-page HTML
substitute. I know how to create a substitute skeleton, that's trivial.
And I know the basic idea here is window.confirm = {my substitute code}.
What I don't know how to do is grab the text and code from each confirm
window that a page issues, and channel it into my substitute, so that the
same message is shown as would be in the original popup and clicking my
substitute confirm and leave page (or whatever) buttons yield the same
result as the original popup.
How can this be done?



EXAMPLE:
You have my extension installed (don't ask what its purpose is, irrelevant).
You start writing a question on StackOverflow, then realize you already
know the answer and go to close the tab.
Normally, a confirmation window would come up asking if you're sure you
want to leave the page.
But because of my extension, instead, the whole page's HTML gets shoved
down a bit to make room for a temporary HTML confirmation box is shown
with the same text and the same two buttons that yield the same two
results when clicked, all in-page. No pop-up.

No comments:

Post a Comment