473,395 Members | 1,641 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,395 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 28917
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.