• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

put javascript method in body tag and its not returning anything

 
Vas Miriyala
Ranch Hand
Posts: 114
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65125
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Vas Miriyala
Ranch Hand
Posts: 114
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 114
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 114
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot for your valuable replies.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic