Exit Feedback Popup when someone click on tab "x" - javascript

Can someone help me with a JavaScript code to show an exit popup when someone clicks on tab "x" to leave that specific page/or website only. (not asking about intent exit pop up). I need to take the userfeedback on my order form to find out if he is happy with the prices. I want to integrate it with contact form 7. Using wordpress. Asking it after 5 hours of search around web.
Thorough help is appreciated.

You can use the beforeunload event (https://developer.mozilla.org/fr/docs/Web/Events/beforeunload) :
$(window).on('beforeunload', function () {
alert('Exit site')
});

You can use the beforeunload event to show a form
$(window).on('beforeunload', function () {
$('.feedbackform').show();
});
on close of the feedbackform you close the page

Related

how to prevent window back button and close tab with javascript

now im doing laravel project. i want to implement javascript code only for preventing the back button and close tab window. i read the article that we can use onbeforeunload(). but this code not suitable with me. because the warning message will display when i want to go to another link menu on my site..
here is my code
window.onbeforeunload = function() {
return "Do you really want to leave?";
};
above code still have problem to me :
i must click at list 1 time on the side. then click close tab, so the pop up will display. if i dont click, the pop up not display and directly close the tab.
im using opera browser but the custom message not display same as what i type. it display "Changes you made may not be saved.". How do i could display the sentence as same as i type?
is there any other code that just prevent only for back button and close the tab? so went i want to navigate to other link menu on my site, the warning message not display.
please help
//you should $event.return = "";
window.addEventListener("beforeunload", function ($event) {
return $event.returnValue = "";
})

Adding additional function to exit page popup message

I want to add an additional function to a basic plain javascript exit page popup. Basically, I have my page set up so when a user tries to exit the page a message will appear saying "do you really want to leave" with the options "OK" and "Cancel". I want to set it up so when the user clicks OK it will redirect them to another website. I don't have a lot of experience coding so I'm not sure if this is possible. Here is the code that I'm using:
<h1 id="home">Warn before leaving the page</h1>
<script>
// Warning before leaving the page (back button, or outgoinglink)
window.onbeforeunload = function() {
return "Do you really want to leave?";
//if we return nothing here (just calling return;) then there will be no pop-up question at all
//return;
};
</script>
<a href="http://google.com/</a>
Any help will be appreciated, Thanks!
This is something you should avoid doing because it is bad user experience. Also this is a repeat of this post.

How can I prevent the JavaScript Prompt Leaving site From Appearing

Hey guys I am trying my best to figure it out how to remove the Javascript prompt/confirm that says "Do you want to leave this site?" like this:
https://prnt.sc/famast
Basically what's happening here is that when a modal got opened and the user click on "YES" it will redirect to a page. But I don't want the JavaScript confirmation but just redirect it to that page.
Any idea if you know some scripts that could make it happen?
Please help!
As other said above me, you can do it with onbeforeunload:
window.onbeforeunload = function() {
return '';
// The browser shows a pre-defined message so you don't have to write your own
}
You can also use addEventListener, in this way:
window.addEventListener('beforeunload', function() {
return '';
});
See an example (Link updated)

How to show a feed back dialog box ,when closing a website

I tried it with beforeunload of window event.But it shows navigation conformation box.I want to show custom dialog box with textarea to take feedback when closing website.
My code is here,
$(function() {
$(window).bind('beforeunload',function(){
document.write('<textarea ></textarea>');
return false;
});
Please help me to find it with pleasure.
I believe this is about your only option:
$(window).on('beforeunload', function(){
return 'Dont Leave';
});
It appears custom dialogs are not possible when leaving a page. After a little digging I was able to find some other posts to explain. Check this one out, the selected answer explains it in-depth:
Dialog box runs for 1 sec and disappears?
You can't, you can only return the text you want to be displayed, for example:
$(function() {
$(window).bind('beforeunload',function(){
return "Are you sure?";
});

Automatic popup on a web page after a specific delay

I am making a B2C website for elearning. I want that when users come to the website and they have been on a page for more than x seconds( say more than 15 seconds ) then a popup window opens up and this window will have some kind of a help message, say a message like "Questions ? We can help. Please call us on XXXXXXX or write to us at abc#xyz.com" . The popup will have a simple image in it and a close button on top right.
My question is that how can I achieve this behavior of an automatic popup coming after a specific delay , when the user is on the site. Also, I would like to have this popup on specific pages and not the complete site.
Thanks !
Use setTimeout() function in document.ready() and provide your function to it which generates the pop-up.
For more reference, check out http://www.w3schools.com/js/js_timing.asp
just use javascript setTimeout Function :
$(document).ready(function() {
setTimeout(function() {
yourPopupFunction();
}, 15000));
})

Categories

Resources