It can't be this hard, can it? I'm new to servlets and Javascript but
have been programming for 1,000 years. End of biographical summary.
So, from an HTML page, I need to invoke a servlet that returns a text
string, and examine the string using Javascript. So I created an html
form that calls the servlet and directs its output to a frame using
the TARGET atttribute. That works fine, and I can see the text string
in the target frame. But I can't examine the output programmatically
because the servlet is running on a different domain and so I get the
"Access denied" message when I try to get to the contents of the
frame.
Surely there must be a way to call a servlet and grab its output,
without first loading it into a frame? Any help is greatly
appreciated...
-Rick
Bryce (Work) - 07 Apr 2004 21:07 GMT
>It can't be this hard, can it? I'm new to servlets and Javascript but
>have been programming for 1,000 years. End of biographical summary.
[quoted text clipped - 11 lines]
>without first loading it into a frame? Any help is greatly
>appreciated...
I'm not entirely sure what your doing, but maybe this will help.
Try putting your javascript in the onLoad() event. I don't believe
that's called until your page is completely loaded.
--
now with more cowbell
Chris Riesbeck - 08 Apr 2004 00:16 GMT
> It can't be this hard, can it? I'm new to servlets and Javascript but
> have been programming for 1,000 years. End of biographical summary.
[quoted text clipped - 7 lines]
> "Access denied" message when I try to get to the contents of the
> frame.
You could have the servlet send a page with Javascript code
to set a variable in your frame, but this doesn't really work
because you don't know when the page has finished loading.
So instead have the servlet send a page to that other frame
that calls a function in your frame in the BODY onload, e.g.,
<html>
<body onload="myFrame.myFunction('servlet data')">
</body>
</html>
Watch out for nested quotes.
Rick - 08 Apr 2004 13:10 GMT
Detecting when the target frame loads is not the problem. I have code
in the target frame "onload" event and that fires as advertised. The
problem is that Javascript will not let you access anything in that
frame if its source was a different server than the one that served up
the main window. In my case, the servlet runs on a different server
within my organization.
So even though I can see the servlet's output in the frame (it is XML,
by the way), the javascript code can't see it. I just want to examine
the contents of the frame to see if the servlet returned "it worked"
or a "it didn't work."
My thoughts are that there might be a way to call the servlet and
capture its output in a string variable, instead of directing the
output to a frame. But I haven't been able to come up with a way to do
that.
-Rick
Bryce (Work) - 08 Apr 2004 17:30 GMT
>My thoughts are that there might be a way to call the servlet and
>capture its output in a string variable, instead of directing the
>output to a frame. But I haven't been able to come up with a way to do
>that.
You are incorrect. I don't believe there's a way to do a post in
javascript into a variable. I think that's a security thing, having
Javascript call outside domains.
So you may need to go back to the drawing room.
Good lu ck
--
now with more cowbell
Chris Riesbeck - 08 Apr 2004 19:16 GMT
> Detecting when the target frame loads is not the problem. I have code
> in the target frame "onload" event and that fires as advertised. The
> problem is that Javascript will not let you access anything in that
> frame if its source was a different server than the one that served up
> the main window. In my case, the servlet runs on a different server
> within my organization.
You can set the document domain in each frame in Javascript to a suffix of
the full domain of the source. So if one frame is coming from
foo.whizzo.com and another from baz.whizzo.com, do
document.domain = "whizzo.com";
in both frames.
Rick - 09 Apr 2004 15:11 GMT
Chris Riesbeck <riesbeck@cs.northwestern.edu> wrote in message news:<riesbeck-> You can set the document domain in each frame in Javascript to a suffix of
> the full domain of the source. So if one frame is coming from
> foo.whizzo.com and another from baz.whizzo.com, do
>
> document.domain = "whizzo.com";
>
> in both frames.
Thanks, I may have to take this approach. I didn't write the servlet
and will have to pull teeth to get the guy who did to change it, which
is why I was looking for a different solution.