wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes put javascript method in body tag and its not returning anything Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "put javascript method in body tag and its not returning anything" Watch "put javascript method in body tag and its not returning anything" New topic
Author

put javascript method in body tag and its not returning anything

Vas Miriyala
Ranch Hand

Joined: Sep 14, 2009
Posts: 114

Here what actually i am doing is that I am catching the popup window close button event by placing a javascript method in <body> tag and this is working fine.
the problem i am facing is that when i write return statement inside the javascript code,its not returning to the previous page just returning to the root page.I am sure i missed something ..guys any idea..
these are my codes(testing it in IE8)



html page
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60780
    
  65

The term "root page" has no meaning. Please be more precise in describing your issue.

I suspect what you want is: return false;

Also, please make sure indentation is correct when posting code. The indentation in your posted code is horribly wonky.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Vas Miriyala
Ranch Hand

Joined: Sep 14, 2009
Posts: 114

thanks a lot for your reply and my apologies for that.well I tried as you said writing return false but it did not worked.The actual scenario is ,I have a page(parent page) with one button called popup,when user clicks on the pooup button,(the child page)the popup window will appear and the popup window contains a text field which is mandatory field.if the user clicks on a popup window close button without entering text in a textfied we need to display a alert message.
I am done up to the displaying the alert message,but when user clicks onthe ok button of alert message box its returning to the parent page,but i dont want to that happen,I need to show the popup window untill user enters the text.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Your code is not even close to being how onbeforeunload works. Look at some docs: https://developer.mozilla.org/en/DOM/window.onbeforeunload

Eric
Vas Miriyala
Ranch Hand

Joined: Sep 14, 2009
Posts: 114

thanks for your Link and as you suggested I followed the code as it is in the link.then also i could not bale to do below are my codes


if i have writeen jusr "return null" then its also returning to the previous page.Is there anyway to make it work?
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
There is NO WAY to prevent the user from not leaving the page. That is how a browser works. IF they press Ok, they will go to wherever the page is going to. If they push cancel, they will stay on the current page.

If you need to force input, than you SHOULD NOT use a pop up. Use a modal layer in the orgainl page. An example is jQuery UI dialog.

Eric
Vas Miriyala
Ranch Hand

Joined: Sep 14, 2009
Posts: 114

thanks a lot for your valuable replies.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: put javascript method in body tag and its not returning anything
 
Similar Threads
How to define focus() method in JS
serious problem about script loading
Is it possible to debug java code in my jsp page using Mozilla Fire Bug
handling onclick event by creating buttons dynamically
Alert