disable javascript popup on refreshing page - javascript

I have written code like this to throw a pop up when my website is closed. But this throws the pop up even if i refresh my page. Please help me to throw popup only when i close the browser of that website. (disable popup on refreshing page)
<body onunload="javascript: exitpop()">
<script type="text/javascript">
function exitpop()
{
my_window= window.open ("","mywindow1","status=1,width=600,height=400");
my_window.document.write('<h1>My Team</h1><p>Thank you</p><p>If you accidentally closed website click here to go back to our website</p>');
}.

onUnLoad is called on a refresh because the browser is requesting a new page (well, the same page in the case of a refresh, but it is still a new call).
I am not sure if there is a way to check where the user is going next, but if there is you could compare it to their current url, if they are the same then the user is just refreshing and the script doesn't need to be run.
Good luck

Sadly, this is not possible. To the browser, it is essentially the same action.
However, if you just use a confirm() box, you can catch a user that is trying to leave without linking them back. If they are refreshing or if they really want to leave, hitting "OK" will allow that action to occur.
Let me know if you need this explained further.

Related

How to make a postback when the user clicks the back button?

I have a webforms web app, and all I need to do is, when a user clicks on the browser back button, I want to make a post-back or reload my page so it makes the post-back itself so new data is loaded.
I am using a library called jQuery-backDetect
which allows me to detect browser's back button click and I try to do is to make a post-back using __doPostback('arg1', 'arg2'). But it won't work at all.
And the strangest thing here is that, if I have the browser's debugger (in developer tools) open, or I pause the code execution using a breakpoint, it works perfectly. Here is a simple code I have written:
$(window).load(function(){
$('body').backDetect(function(){
// Callback function
debugger;
__doPostback('arg1', 'arg2');
});
});
I have tried to go through all the question here but they didn't help.
As strange as the question sounds, I really hope someone can help me. Thanks
You might consider wrapping the page content in an UpdatePanel, that might help create the behavior you are looking for.

Redirect Page In Chrome Without Confirmation Dialog

I'm having an issue with JavaScript, especially in Google Chrome, where, when I redirect to another page, I receive a Confirm Navigation dialog asking if I want to leave or stay on the current page. In my code I'm calling alocation.replace(); method.
My goal is to bypass Chrome's Confirm Navigation dialog and, at the same time, avoid breaking the Back button in the redirection process. Does anyone have any suggestions?
Try using window.location.href="your url" Example

how to open web application in a browser without navigation buttons

I have a web application, and I want to disable the Back button.
I read and found that I can open the browser without the navigation controls with the function window.open(...).
This is the code:
window.open (mywebappURL,"mywindow","status=1,toolbar=0");
I tried to put it in my Main.Master page, but I get an infinite loop and the new window is opened as a popup window of my application.
Does anyone knows where should I put this code to get my web application opened in a browser without navigation buttons?
Thanks,
Inbal.
try this on the link's onclick() event
function openPopup(){
var pathname = (window.location.pathname);
window.open(pathname+'somePopup.html','','width=800,height=450,resizable=yes,dependent,screenx=80,screeny=80,left=80,top=20,scrollbars=no');
return false;
}
and in the html
click me
To answer your question directly, make sure the window you're opening is a different URL than the window that's initially visited. So your visitor might arrive at www.example.com/index.html which then opens www.example.com/popup.html
If you open index.html again, the new copy will immediately open a popup, which will immediately open a popup, and there's your infinite loop.
However, as several people have commented already, this is generally discouraged. Among other disadvantages to this approach, popup blockers will likely interpret this as trying to launch a popup advertisement, forcing your visitors to recognize what's happened and change their settings.

how to keep only one tab or page for every user in the browser?

I'm writting a real-time chat application.
And I want to keep only one tab in the browser(chrome)
(firefox seems to act like that).
I've tried using cookie..
below is the js code using jquery.cookie.js
if($.cookie("online")){
window.close();
}else{
$.cookie("online",1);
}
But I did't get what I want.After refreshing the page will terminate the tab anyway.
and the cookie will stay alive until the browser is closed but not the tab.
Can anybody help me?
You cannot programaticaly close the current tab unless you opened it with Javascript.
This would also be very confusing for visitors, as they would get no information as to what happened, the window would simply close on them when they tried to open it.
Instead, consider displaying an error message or splash page telling them why they are not getting a second copy of the chat room, and telling them to return to the previous window. This would be much more user friendly.

Capturing F5, Back, Forward, clicking on link actions

I want to show a popup when a user close the browser and that popup will redirect to some google survey that we need to do.
Currently by using onbeforeunload function in JavaScript it's prompting me the popup but I only need popup when the user closes the browser or they enter a new url.
Is there any way to prevent this function to not fire when page is refreshed, or user goes back or forward and if it can be done then how will I redirect to a survey page. Or if we can't prevent then there is any logic to do this.
No, this is not possible. These events are outside your control for security reasons.
You're probably best off finding a different solution for your problem.

Categories

Resources