Forums Register Login

javascript code is not called in jsp page

+Pie Number of slices to send: Send
Hi,

I have jsp page which actually redirect to another jsp page....
I need to run some javascript code before redirecting to another page

But it seems script got skipped & it goes to desired page.

code snippet:

I am expecting an alert "testing" before redirect to another page.

Thanks in advance
+Pie Number of slices to send: Send
The code you are showing will not even compile. Please be sure to PostRealCode ⇐ click this

Regardless, what you are doing is not legal. You are just lucky that it does not result in an IllegalStateException.

What are you really trying to accomplish? Whatever it is, this isn't the way to do it.
+Pie Number of slices to send: Send
Hi Abishek, welcome to javaranch.

Your javascript code runs in the browser and you are doing a server side redirect. So the javascript is never sent to the browser which is why it never runs. If you want the javascript to run, you'll have to redirect the browser in javascript like
window.location=${param.url}
or something else like that after the alert message

[edit: bear beats the human (just kidding)]
+Pie Number of slices to send: Send
Actually i need to track page through google analytics
So google analytics has provided me javascript code which i need to put in the page for which tracking is required

It is working with normal jsp pages but not with jsp page with redirection (as i need to track that page also per the requirement)

I understand from previous reply, server side redirection happening thats why javascript code never gets called/run

So i want that before redirection, my javascript code runs so that google analytics track/capture the page.
+Pie Number of slices to send: Send
There should be no such pages. If all the page is going to do is to redirect, then this is something that should be done in the servlet controller before any JSP is invoked at all. Since this situation should never occur, your problem is solved.
It is an experimental device that will make my mind that most powerful force on earth! More powerful than this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 4773 times.
Similar Threads
Validate
How to redirect to a new page using JSP?
How to show a pop up window from a servlet
wrestling with json
not getting alert msg in jsp
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 09:53:23.