Accessing the request attribute in the onLoad() event.

S

Sunny

Hi,
I have cr8ed a javascript function in the head section of a jsp
page.

<!--
function go(theURL) {

alert(theURL);

if (theURL!=null){

window.open(theURL,'popup','scrollbars=yes,resizable=yes,width=800,h

eight=600');
}
}
//-->

This function receives a url and displays it in the pop up window.
This function is called by the onLoadevent() during the loading of the
page. The parameter passed is obtained using the request attribute in
the foll. manner.

<body text="#003366" onLoad="javascript:go(
<%request.getParameter("val");%>)" >

The alert() function in the javascript method display "unspecified"
message in this example.
However, accessing the request attribute and storing it in a string
gives me the required result.
ie. String url = <%request.getParameter("val");%> gets the correct
url.

Just want to know if it is possible to use the request attribute
during the onLoad() event.

cheers







String name=request.getParameter("val");



<a href="javascript:go('<%=url %>')">Click to view</a>



<jsp:forward page = "centre1.jsp">

<jsp:param name = "val" value="<%= url %>"/>

</jsp:forward>



<%/*response.sendRedirect("centre1.jsp");*/%>
 
M

Michael Winter

I have cr8ed

Is it really that difficult to type 'eat' instead of '8'?

[snip]

It's not necessary to hide scripts from browsers any more. Remove the
comment delimiters.

[snip]
The parameter passed is obtained using the request attribute in
the foll. manner.

Wow! You've now saved a whopping six characters from your abbreviations.

Please write in full.
<body text="#003366" onLoad="javascript:go(
<%request.getParameter("val");%>)" >

The 'javascript:' prefix isn't needed. It's just a label in all but one
browser, and it doesn't matter even in that case most of the time. Remove
it.

[snip]
Just want to know if it is possible to use the request attribute
during the onLoad() event.

You seem to be confused as to what happens when. You don't use request in
a load event. By the time the client sees the page, the server has
substituted the code for a value of some kind, and that is what's used.

This is why showing server-side code is useless. It doesn't actually show
the problem because it has no bearing on client-side execution. It's the
values that *result* from the server-side code that matter.

I suspect that the problem is simply an unquoted value. I haven't used
JSP, but I assume that the code above returns an unquoted string, correct?
If so, just place a single quote before the <% and another after the %>.
If that doesn't help, post what you get when you view the source in the
browser.

[snip]

Mike
 
M

Michael Winter

[snip]
It's useful though, since some site-search engines are prevented to
index script blocks through this. A good example is PHPdig.

In that case, do what you probably should be doing, anyway. Move the
script into an external file.

Mike
 
G

Grant Wagner

Sunny said:
This function receives a url and displays it in the pop up window.

No, that may be what you intend it to do. However, in a lot of browsers it won't do
anything except possibly warn the user a Web page tried to open a new window and the
attempt was captured and suppressed. This list of browsers includes, but isn't
limited to:

IE < 6.0.2900 with the google toolbar, the newest AIM w/popup blocker installed or
any other popup blocker (Window Washer, some Symantec software, Proxomitron, etc)
IE 6.0.2900 in it's default configuration
Any Gecko-based browser (Mozilla, Netscape, Firefox, Camino) in it's default
configuration
Opera 7.54 if configured to "Block unwanted pop-ups" (I haven't bothered to check,
but I'd bet it will start coming configured that way in 7.6)

All these browsers and browser add-ons come with this option because people are sick
of new windows popping up simple because they chose to visit a Web site.

Of course, if this is for an Intranet application, and you control the browsers
used, and their configuration, then by all means continue to open a new window on
page load.
Just want to know if it is possible to use the request attribute
during the onLoad() event.

Sure you can use a server-side request in an onload event:

<% String val = request.getParameter("val"); %>
<body onload="alert('<%= val %>');">

As some others have said, it's most likely that you didn't quote the string that
gets returned from request.getParameter(). In other words, you're doing this:

<% String val = request.getParameter("val"); %>
<body onload="alert(<%= val %>);">

(note the missing inner single quotation marks on the call to alert())
 
S

Sunil Kamath

Sorry, but at the end of the day, typing full words (when one can do
with abbreviations and get the message across)is the last thing on my
mind. hehehehehe!!!!

Aneways, When i use <body text="#003366" onLoad="javascript:go(
'<%request.getParameter("val");%>')" >
the source in the browser is
<body text = "#003366" onLoad = "javascript:go('')" >

and it shows an empty alert box. It also goes on to pop up an empty
window.



<%
String name=request.getParameter("val");
out.println("url= "+name);
%>
Using the above statement in the jsp body does return me a proper url
which is printed on the same page.



cheers
Sunil
 
L

Lee

Sunil Kamath said:
Sorry, but at the end of the day, typing full words (when one can do
with abbreviations and get the message across)is the last thing on my
mind. hehehehehe!!!!

You're asking people to help you.
You owe them the courtesy of making your post as easy to read as possible.
 
M

Michael Winter

[snip]
the source in the browser is
<body text = "#003366" onLoad = "javascript:go('')" >
and it shows an empty alert box. It also goes on to pop up an empty
window.

<%
String name=request.getParameter("val");
out.println("url= "+name);
%>
Using the above statement in the jsp body does return me a proper url
which is printed on the same page.

Then your problem must be on the server, and not with Javascript.

Ask in the JSP forum on Sun's website. I also believe JSP is on-topic in
one (or possibly more) of the comp.lang.java.* groups.

Good luck,
Mike
 
T

Thomas 'PointedEars' Lahn

Ranbir said:
It's useful though, since some site-search engines are prevented to index
script blocks through this. A good example is PHPdig.

Then this app(s) is/are b0rken. It/They should not index script elements
at all (or at least should provide a pref to do so), whether "commented out"
or not.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top