473,320 Members | 2,073 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Accessing the request attribute in the onLoad() event.

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,resizab le=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");*/%>
Jul 23 '05 #1
9 28908
On 30 Sep 2004 03:58:43 -0700, Sunny <su************@hotmail.com> wrote:
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

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2
Hi,

In article <opse428pr2x13kvk@atlantis>, Michael Winter wrote:
On 30 Sep 2004 03:58:43 -0700, Sunny <su************@hotmail.com> wrote:

<!--


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


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

Ranbir
Jul 23 '05 #3
On Thu, 30 Sep 2004 14:27:37 +0200, Ranbir Kaur <sm****@yahoo.com> wrote:

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


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

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #4
Sunny wrote:
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())

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #5
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #6

oops, did not use the '=' in <%=....%>. got tht working now.

Thanks
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #7
On 30 Sep 2004 23:29:59 GMT, Sunil Kamath <su************@yahoo.com> wrote:

[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

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #8
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.

Jul 23 '05 #9
Ranbir Kaur wrote:
In article <opse428pr2x13kvk@atlantis>, Michael Winter wrote:
On 30 Sep 2004 03:58:43 -0700, Sunny <su************@hotmail.com> wrote:
> <!--


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


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
--
Clarity of thought before rashness of action.
Jul 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Mike Hnatt | last post by:
I'd like the focus to be on "mycontrol" when the page is first loaded. I'm getting an undefined error and am assuming that I can't do this in the body ONLOAD event because the control is not yet...
2
by: Bender | last post by:
Hi, I am wanting to capture an onmousedown event without firing the body tags onload event. Also, if anyone could explain why this happens that would be excellent. I can't see how an...
4
by: Pai | last post by:
hello there, I am trying to rersize the window it works find in IE but doea not work with mozilla window.attachEvent(onload,MWSOnLoad); window.onload = function (MWSOnLoad) { alert('hello');...
6
by: Brian | last post by:
Hi everyone, I'm writing a function (in javascript) that needs to do one thing if the page has not loaded, and another (different) thing if the page has already loaded. I'm looking for a way...
1
by: Adam Ratcliffe | last post by:
I'm trying to come up with a solution for detecting when an image, loaded by a script, has completely loaded. The Image.onload event is fired after the image has loaded in Firefox but before...
5
by: Andy Fish | last post by:
Hi, I have an asp.net web application which uses a pop-up form that works a bit like a dialog box. when the user clicks "OK" it does a postback (basically a form post if you don't know .net) to...
6
by: pronerd | last post by:
Hi, I am trying to dynamically set an event handler across frames. I have no problems setting properties across frames doing something like parent.ToolMenuFrame.location.href =...
6
by: Daz | last post by:
Hello everyone, I would like to open a child window from the parent, and add an onload event listener to the child window which will tell the parent when the document has loaded. As far as I...
1
by: webgour | last post by:
Hello, I would like to create an onload event within my object. The following works fine : function TEST() { this.image= new Image(); } TEST.prototype.Initialize = function()
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.