Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Prevent a visitor from navigating away from curent page

Posted on 2011-09-06
21
Medium Priority
?
469 Views
Last Modified: 2012-05-12
Hello and good day,

I have a web page with a html form in it.
The form has some mandatory fields too with submit button.
Now this is what i wanna achieve...
If a visitor arrives on this form page and tries to leave the page without submitting the form (either by typing a new url in address bar or by clicking back button) then the visitor should be prevented from navigating away from the form by displaying a small css html window (NOT the typical Javascript alert) with a message asking if visitor needs any assistance with a text area and 2 buttons (Yes button and Navigate away button). If he presses yes button then all that he types in the textarea will be submitted to website admin and if he wishes to navigate away from page he can by clicking on Navigate away button.

Can this be done?
If yes can you please upload a complete working code (a basic code at least)
Thanks
kansun
0
Comment
Question by:kansun
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 3
  • +3
21 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 400 total points
ID: 36491514
>Can this be done?

Not really.
Do you want something working 100% of time?
0
 
LVL 15

Assisted Solution

by:WalkaboutTigger
WalkaboutTigger earned 400 total points
ID: 36491554
<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>

from

http://www.4guysfromrolla.com/demos/OnBeforeUnloadDemo1.htm?name=&age=

Modify the function to call the render the appropriate window
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36491559
@WalkaboutTigger :

small css html window (NOT the typical Javascript alert)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 82

Expert Comment

by:leakim971
ID: 36491565
additionaly onbeforeunload don't work on all browsers.
0
 
LVL 19

Assisted Solution

by:moagrius
moagrius earned 800 total points
ID: 36491567
you can only use the traditional javascript modal dialog - you can't customize it.  the event is window.onbeforeunload, which is managed by the browser (and there's nothing you can do about it), but is the only thing that can interrupt a page exit.

here's a little info on it:  http://upshots.org/javascript/window-onbeforeunload
0
 
LVL 16

Expert Comment

by:HagayMandel
ID: 36495035
It's the worst user experience you can provide!!
Do the best you can to attract visitors, but don't try to prevent them from navigating away!
0
 
LVL 29

Expert Comment

by:Badotz
ID: 36495808
You cannot force the user to do anything. If you make it difficult to leave, my guess is they will not be back.
0
 

Author Comment

by:kansun
ID: 36512802
Hi My friends,
I expected a solution. But i just got few advices here.
:-)) Can anyone provide a soln for this.... thx
0
 
LVL 29

Assisted Solution

by:Badotz
Badotz earned 400 total points
ID: 36512912
>>I expected a solution.

You cannot prevent the user from leaving your page. Worst case, she will close the browser window and never return to your site.

You can train your users on the proper way to exit your page, and explain the consequences for not doing so.
0
 
LVL 19

Assisted Solution

by:moagrius
moagrius earned 800 total points
ID: 36512999
Badotz is correct.  Sometimes the answer is that there is no solution.

You can only interrupt page exit using window.onbeforeunload.  Doing so will result in a browser-generated modal dialog.  This cannot be replaced with an HTML fragment.

There's no other answer.
0
 
LVL 29

Expert Comment

by:Badotz
ID: 36513049
And onbeforeunload may not be supported in all browsers.
0
 

Author Comment

by:kansun
ID: 36891884
I've requested that this question be deleted for the following reason:

no answers
0
 
LVL 29

Expert Comment

by:Badotz
ID: 36891885
The answer is, "You cannot prevent the user from leaving."

What more do you want?

0
 
LVL 82

Expert Comment

by:leakim971
ID: 36892071
99% of time for this question the member want a << solution >> not a << right answer >>...


0
 
LVL 29

Expert Comment

by:Badotz
ID: 36892128
<waiting_for_the_envelope>
...and the solution is...
</waiting_for_the_envelope>
0
 

Author Comment

by:kansun
ID: 36895092
thank you
0
 
LVL 15

Expert Comment

by:WalkaboutTigger
ID: 36895173
There are no US-legal solutions to your question, unless you control the machine from which the user is browsing (like a kiosk machine).  I presumed from your question, however, that this was not the case.
0
 
LVL 29

Expert Comment

by:Badotz
ID: 36895659
>>unless you control the machine from which the user is browsing (like a kiosk machine)

So, what is the "solution" in that case?
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question