Click to See Complete Forum and Search --> : Trying to obtain the 'src' returned by a servlet
jovialjonny
07-10-2003, 04:33 PM
Okay this is a tricky one to explain so I hope someone has done something similar before!
I have an iframe on my page (say, frame1), at the click of a button a second iframe is created (frame2) with exactly the same contents as the first (frame2 is built dynamically and the 'src' attribute is set to be the same).
This works fine if I am using regular webpages however there is also a form that users can submit on this page. The form's action sends it to a servlet which returns a dynamically generated webpage that is targeted to frame1. It appears in frame1 with no trouble but if I try to obtain the 'src' to display the contents in frame2 I just get nothing- an empty string is what seems to come up if I run an 'alert' on it- there is no error message or anything. Does anyone know how I can get the contents of frame1 to display in frame2?
(I know this is a bit abstract but any advice would be great thanks!)
Khalid Ali
07-10-2003, 07:49 PM
Once the servlet returns the HttpResponse to the browser its not a static file,its dynamic contents,which I seriously doubt that that you can use src element their unless you resend the quesry to servlet.One thing that might be a possibility is to get the contents using DOM methods
frameName.document.getElementsByTagName("body"[0].innerHTML
jovialjonny
07-11-2003, 11:28 AM
I'm gonna try to implement that but I've another question that may give me a solution to this problem:
What I actually need to recreate the page is the url submitted to the servlet, its using a GET method so the url will have the form variables in it. If I could get the servlet url with the form variables included I should be able to reporduce the iframes contents.
If the servlet was returning to a blank page the url would appear in the address bar (I think??) but seeing as its returning to an iframe thats not the case. Do you know how I could access the full url?
Could I obtain it in the opening page that submits the form, or in the child page that opens afterwards where the result of the submission is displayed?
Khalid Ali
07-11-2003, 11:59 AM
The returned url should of the servlet that sent the response...
jovialjonny
07-11-2003, 12:02 PM
Originally posted by Khalid Ali
The returned url should of the servlet that sent the response...
:( Sorry what?
jovialjonny
07-11-2003, 12:05 PM
I tried to obtain the url of the iframe like so:
var ifrm = document.getElementById("frm1");
alert(ifrm.url)
but it comes back as undefined.
Khalid Ali
07-11-2003, 12:05 PM
lol..oops...I was bizzy dealing with this spammer...
anyways..what I meant was that the url that will be seen in the address bar will of the servlet that generates the response.
jovialjonny
07-11-2003, 12:10 PM
Okay I'm starting to think Im making some reference mistake here because I just put in this:
(frm1 is the iframe the servlet returns to)
var ifrm = document.getElementById("frm1");
alert(ifrm.document.body.innerHTML)
And it returned the HTML of the entire page, not anything from the iframe within the page. Can I get the innerHTML of the iframe itself?
Khalid Ali
07-11-2003, 12:14 PM
instead use this to get the innerHTML
iframe.document.getElementsByTagName("body")[0].innerHTML
I think this will return the body htmlfor you.
jovialjonny
07-11-2003, 12:51 PM
That worked! thats great thanks:D
jovialjonny
07-11-2003, 01:13 PM
I will probably still need the complete url though ie.containing the form variables. Do you know of a way I can access that, either in the page that submits the form or in the page that opens to display the results.
I don't know if this is possible or not so please let me know if you have any idea how I could do this.
Khalid Ali
07-11-2003, 01:30 PM
You are welcome..:D
Originally posted by jovialjonny
I ..... I could do this.
Honestly I am not quite sure what is you want when you say this.
1.you have main page containing a iframe1.
2.you submit your form from main page to servlet which returns the response to iframe.
Which url are you looking for
The url of the main page or the url of the iframe(because iframe should have theurl of the servlet to which you submitted the form.)
jovialjonny
07-11-2003, 02:26 PM
Sorry for the lack of clarity..
I have a main page that just contains some text fields and a submit button.
The action of the form is to send the form variables to a servlet, at the same time a child page is opened in which there is an iframe. The servlet returns a dynamically generated page to the iframe. What I need to happen is that the user can click a button that opens a 2nd iframe containing the same contents as the first (it will be used for comparing page contents n stuff).
If I could access the url that was submitted to the iframe (i.e.with the form variables included) I could set this to be the 'src' of the 2nd frame.
What I want to know is can I access the url that was submitted to the servlet with the form variables included?