i have a jsp file .whenever user closes the screen a pop up with custom message and two custom buttons ( continue and cancel ) should appear .by clicking continue button u should go to another page .and cancel button to stay on the same page .......plz help me out how cud these be achieved ..
Is there a way to change default message I am getting 'Are you sure you want to navigate away from this page?' and then 'Press OK to continue, or Cancel to stay on the Current page.' Can I only display 'my message' in between this two messages?
I am using below javascript codes:
<script type="text/javascript">
function beforeClose()
{
return "my mssage...";
}
window.onbeforeunload=beforeClose;
</script>
check out this thread for your answer
How can I override the OnBeforeUnload dialog and replace it with my own?
Related
When user click on browser back button, user will see a alert message for that I am using below code.
window.onbeforeunload = function () { return "If you want to go back to previous page Please use Previous step Button in below"; };
But in the code I have written "If you want to go back to previous page Please use Previous Step Button in below". This message is not displaying in alert box,instead of that message it is showing another message:
.
How can I display my own message in the alert box?
You will need to put javascript/jquery code you want to use on a handler for beforeunload event
window.addEventListener("beforeunload", function (event) {
//your code goes here. Create modal window or whatever you need
});
I have a page and I named it to mypage.php. I have a table MyTable with a column STATUS. I want to update the status to T when the user enters to the page and change to F when the user leaves or close from the page.
I tried with onbeforeunload with JS. Help me any way.
Try
window.onunload=function(){
/......when user closes..../
}
window.onload=function(){
/....when user enters page.../}
I think you should try the "onfocusout" or "blur" event if you want to update it when the user goes on another tab and not only when he close your tab. Put the onfocusout on the body tag and it will fire when the user will exit your tab, by switching to another tab or by closing yours.
When I press and hold the browser back button or just right click the back button I can go back pages. But I need to disable it. Is there any way to do that with javascript or jsp
Open A New Window without Back Button
browser-back-button-viralpatelThis one is very crude technique. But in some case it works like charm. All you have to do is to open the webpage in a new window. This window doesn’t have back button at all because we have hide the toolbar.
This technique does work in some case but user has still a workaround to navigate to previous page. Most of the browser have options of Back in context menu. Thus user can still right click on the page and click Back to go to previous page. We will shortly see the workaround for this issue also.
Following is the code to open webpage in a new window have no toolbar (Back/Next buttons).
window.open ("http://viralpatel.net/blogs/",
"mywindow","status=1,toolbar=0");
Also it is possible to disable the right click on any webpage using Javascript. Add following code in the webpage.
<body oncontextmenu="return false;">
Disable Back functionality using history.forward
This is another technique to disable the back functionality in any webpage. We can disable the back navigation by adding following code in the webpage. Now the catch here is that you have to add this code in all the pages where you want to avoid user to get back from previous page. For example user follows the navigation page1 -> page2. And you want to stop user from page2 to go back to page1. In this case all following code in page1.
<SCRIPT type="text/javascript">
window.history.forward();
function noBack() { window.history.forward(); }
</SCRIPT>
</HEAD>
<BODY onload="noBack();"
onpageshow="if (event.persisted) noBack();" onunload="">
The above code will trigger history.forward event for page1. Thus if user presses Back button on page2, he will be sent to page1. But the history.forward code on page1 pushes the user back to page2. Thus user will not be able to go back from page1.
Warn User if Back is Pressed
You may want to warn user if Back button is pressed. This works in most of the cases. If you have some unsaved form data, you might want to trigger a warning message to user if Back button is pressed.
Following Javascript snippet will add a warning message in case Back button is pressed:
window.onbeforeunload = function() { return "You work will be lost.";
Reference
just use
window.onbeforeunload = function() { window.history.forward(1); };
or if u like to warning user
window.onbeforeunload = function() { return "Back button is not available!"; window.history.forward(1); };
Let's say I have an update page in HTML5 and if the user edited a field, I want to show a pop-up whenever the user will exit the page (by clicking on another link) without clicking the update button. The pop-up will confirm if the user wants to save his edits or if the user declined, simply continue on the link he clicked before. How to achieve this in HTML5/JavaScript? Is there any function that preempts redirects? Thanks.
Use the onbeforeunload event.
Check out the demo: onbeforeunload Demo
JS code:
<script language="JavaScript">
window.onbeforeunload = confirmExit;
function confirmExit()
{
return "You have attempted to leave this page. If you have made any changes to the fields without clicking the Save button, your changes will be lost. Are you sure you want to exit this page?";
}
</script>
When one scenario is done, the page refreshes (in the website there is a javascript modal implemented before refreshing the page which asks the user "Are you sure you want to leave the page?"). I need to confirm that modal. But when I create the step for that, I always get this error:
Then User clicks "Leave this page" button in the popup at online reg form
no alert open
(Session info: chrome=35.0.1916.114)
and the code
And(/^User clicks "([^"]*)" button in the popup at online reg form$/) do |button|
wait = Selenium::WebDriver::Wait.new
alert = wait.until { page.driver.browser.switch_to.alert }
alert.accept
end
Does anyone know how to handle this?
You need to override the confirm dialogue method in javascript to always return true
page.evaluate_script('window.confirm = function() { return true; }')
use this line before the line of code that triggers the dialogue to popup and it will always accept it no more steps needed :)