I am facing a problem in a analytics project I am developing.
I want to trigger a event when any type of modal opens on a specific page, the page is unknown, the type of modal can be anything in a page.
I do not want to use Google Analytics.
I am trying to find a solution for this since a long time.
I have tried for window.open, but I do not want only for window.open. It should Work for all type of libraries and modals out there.
This is what I have done so far,
<script type="text/javascript">
var windowOpen = window.open;
window.open = function(url, name, features, replace) {
alert("opening a window");
// do other stuff here
windowOpen(url, name, features, replace);
}
document.getElementById("myBtn").addEventListener("click", function() {
window.open("http://www.w3schools.com");
});
</script>
Any help would be appreciated, thanks in advance.
EDIT1 : I thought of one thing we could do, that is we could look for some changes in the DOM. Because usually a pop up adds a DOM into the existing DOM to enable popups (but not always necessary).
element with styling to make it behave like a modal, and there would be no reliable way to detect that. You could however detect commonly used techniques, such as those you mentioned, but you'd need to handle each one as a separate case.
– Highly Irregular Feb 04 '15 at 09:04