Accessing IFRAME content question

P

Paul Brant

Hi all,

I have a page with an IFRAME in it. From a script in the main ( parent )
page I instruct the IFRAME to load a specific URL. The URL contains
parameters that are processed by the server. The server then writes a result
cookie into the content destined for the IFRAME.

I am having issues accessing the cookie. If I use a debuger I can see the
cookie via a quickwatch looking at window.frames['name].document.cookie
however when I run the code the same variable is empty. Does anyone have any
ideas??

Many thanks for your responses//

Paul
 
E

Erwin Moller

Paul said:
Hi all,

I have a page with an IFRAME in it. From a script in the main ( parent )
page I instruct the IFRAME to load a specific URL. The URL contains
parameters that are processed by the server. The server then writes a
result cookie into the content destined for the IFRAME.

I am having issues accessing the cookie. If I use a debuger I can see the
cookie via a quickwatch looking at window.frames['name].document.cookie
however when I run the code the same variable is empty. Does anyone have
any ideas??

Many thanks for your responses//

Paul

Hi

Is the URL in the IFRAME on the same domain as the mainpage?

Regards,
Erwin Moller
 
M

Martin Honnen

Paul Brant wrote:

I have a page with an IFRAME in it. From a script in the main ( parent )
page I instruct the IFRAME to load a specific URL. The URL contains
parameters that are processed by the server. The server then writes a result
cookie into the content destined for the IFRAME.

I am having issues accessing the cookie. If I use a debuger I can see the
cookie via a quickwatch looking at window.frames['name].document.cookie
however when I run the code the same variable is empty. Does anyone have any
ideas??

The new page in the iframe needs to be loaded before document.cookie in
that frame window can have the new cookies so you need to wait to have
the page loaded.
As you want to access the cookies from the containing window it is best
you define a function there
function processCookies (cookies) {
...
}
and then in the new frame loaded in the iframe you do
if (parent && parent.processCookies) {
parent.processCookies(document.cookie);
}
 
P

Paul Brant

"Erwin Moller"
Paul said:
Hi all,

I have a page with an IFRAME in it. From a script in the main ( parent )
page I instruct the IFRAME to load a specific URL. The URL contains
parameters that are processed by the server. The server then writes a
result cookie into the content destined for the IFRAME.

I am having issues accessing the cookie. If I use a debuger I can see the
cookie via a quickwatch looking at window.frames['name].document.cookie
however when I run the code the same variable is empty. Does anyone have
any ideas??

Many thanks for your responses//

Paul

Hi

Is the URL in the IFRAME on the same domain as the mainpage?

Regards,
Erwin Moller

Hey Erwin,

While I do not specifiy a domain within the server code both pages load from
the same host !

Regards,

Paul
 
P

Paul Brant

Martin Honnen said:
Paul Brant wrote:

I have a page with an IFRAME in it. From a script in the main ( parent )
page I instruct the IFRAME to load a specific URL. The URL contains
parameters that are processed by the server. The server then writes a result
cookie into the content destined for the IFRAME.

I am having issues accessing the cookie. If I use a debuger I can see the
cookie via a quickwatch looking at window.frames['name].document.cookie
however when I run the code the same variable is empty. Does anyone have any
ideas??

The new page in the iframe needs to be loaded before document.cookie in
that frame window can have the new cookies so you need to wait to have
the page loaded.
As you want to access the cookies from the containing window it is best
you define a function there
function processCookies (cookies) {
...
}
and then in the new frame loaded in the iframe you do
if (parent && parent.processCookies) {
parent.processCookies(document.cookie);
}

Hey Martin,

many thanks for your post. I have progressed as a result of it. Given I own
the source to the server I decided to move away from cookies. I am however
ensuring that the document is loaded before proceeding. My iframe now calls
setResult on the following:

var processResult = new function() {
var scratch;

this.setResult = function(result) {
scratch = result;
}

this.getLastResult = function() {
return scratch;
}
}


I see scratch get set. When the parent (main) window then calls
getLastResult i get undefined. If I debug I see the variable set corrently.
Again.. if you have any thoughts I would be grateful.

Paul
 

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
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top