• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Is there a way to catch a browser's event in a JSP ?

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everybody,

My boss asked me if it was possible to intercept a browser events such as BeforeClose and look if some objects remained in invalid state. If they are, to send a message to inform the user about the problem. Since it's an browser's event, I guess it must be implemented in my webpage which is a JSP. Is it possible to do something like that in JavaScript ?

thank you for your help !
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JSP executes on the server in order to format an HTML page to send to the browser.

Browser events must be handled with JavaScript.

Perhaps this article will be helpful in understanding JSP.
 
Leinad Jan
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:JSP executes on the server in order to format an HTML page to send to the browser.

Browser events must be handled with JavaScript.

Perhaps this article will be helpful in understanding JSP.



Yes, I know. That's why I specified in JavaScript at the end of my message. I saw some people suggesting to use onBeforeUpload in the body. But I don't want it to be called each time somebody does a submit.

I'll read your article, but I do understand that JSP are executed on the server to generate the HTML code sent back to the user's browser. But we don't use plain HTML pages in our web application. Even if sometime it is use as much as it was a plain HTML page. I'm not responsable for that sort of design, I'm just maintaining it and adding new features.

Thank you.
 
Bear Bibeault
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's plain HTML by the time it reaches the browser. If you understand that, then I'm not sure that I understand your question.
 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Umm Leinad, let's put it this way: A browser doesn't know what is a JSP (or ASP/PHP/Ruby whatever), it can show only HTML.
A JSP page has HTML content interspersed with scriptlets/expressions/JSTLs which are executed on Tomcat to create HTML content, which is sent to browser. So in the end, our humble browser gets to see just the HTML stuff which it dutifully renders!

So, whatever javascript you want to put in your page, put it in your JSP. It will be untouched by server and sent to browser.

Hope this helps.

Abhishek
 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would suggest you to track each event that causes the browser to close, for example a CLOSE button or the X button at top right corner of a browser. If you handle these events in javascript and execute logic accordingly. For the X button, you can use the mouse pointer position to detect the event. Let me know if you need details on this...

And as suggested above, you need to put your Javascript code inside your JSP.

Cheers
Sid
 
Leinad Jan
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:It's plain HTML by the time it reaches the browser. If you understand that, then I'm not sure that I understand your question.



I'm sorry, I wasn't clear in my statement. I'll try to be clear this time. I'm not a native english speaker, so forgive me for my mistakes and errors. Maybe this thread should move to the javascript forum ? Because except that I need to place the code inside my template, it has nothing to do with JSP. Some people told me to look for info in JSP forums...

Our web application is used for creating, storing and editing informations about schools. When the user is creating or changing information, there are automatic operations done on the data. If everything is correct, the status of the school will be in valid state. But in specific case, it will be invalid.

My boss wants me to send a message to the user about the remaining invalid schools before closing the application in every way possible. And the principal worry is the browser's X button. We search a way to intercept the browser's events in Javascript.

I must be able to intercept an event like "Before Closing".

Sidd Kulk : So, you think I could intercept the events by using the mouse pointer events ? That means I should detect if the cursor is at the top right corner of the screen and if the mouse left button is down.

That sounds interesting. Could you tell me more about that ? The problems I'm seeing are : Can we know the browser's resolution ? How to calculate the space for the button ? How to handle the tabs in FireFox and Internet Explorer ? They can close the application too.

I think the best solution would be to listen the events themselves. In java, we can create events listeners. Can't we do something like that in Javascript ?

Thank you all for your help, and I'm sorry to have post that message in the wrong forum.


Editing :

I've look to some examples, and it doesn't seem to be able to detect the pointer when it is outside of the document ?



 
Of course, I found a very beautiful couch. Definitely. And this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic