PDA

View Full Version : Accessing a pages's element from another page !!!!



codeexploiter
01-15-2007, 03:39 AM
Hi all,

I have two page where the first page is a normal web page which has a link to the second page. If the user clicks on this page he/she will be moved to the second page which actually wants to change the background color of an element present in the first page.

For Example: There are two pages Page A and Page B. Page A has a link to Page B and I want to change the background colour of Page A from Page B.

Don't know whether this is possible but still posting and expecting your valuable thoughts on this issue.

Thanks in advance

CodeExploiter

jscheuer1
01-15-2007, 06:46 AM
You haven't said if these pages are in separate windows, tabs, frames or whatever. I'm not sure about tabs but, generally they would act like separate windows. With frames, as long as you are all on the same domain, you can target the frame document various ways, depending upon where you are doing it from. With windows, the easiest way is if at least one of them have been opened via javascript:


var mywin=window.open('some_page.htm');

so that it could be referenced by its variable name. Care must also be taken to use mywin.document or mywin.window, depending upon if you are accessing the document or the window.

codeexploiter
01-15-2007, 06:58 AM
Hi John


You haven't said if these pages are in separate windows, tabs, frames or whatever.

Sorry for the confusion actually whenever the user clicks on the link available in Page A (first page) Page B (second page) will be loaded on the same window no popup, tab windows available.

Hope this is clear now.

Thanks

Regards

jscheuer1
01-15-2007, 07:18 AM
A server side CMS might be a better choice for this. In javascript, your only real choice would be a javascript cookie, one that is set for the entire domain by page B but read only by page A. You can pass a parameter to page A. But if other pages are involved, they would all have to pick up, maintain and pass along this parameter.

There are several decent cookie units available. The one at:

http://www.quirksmode.org/js/cookies.html

will set and read domain wide cookies. Use the unit on both pages. Set the cookie on page B and read it on page A. The only real tricky part is making sure to test for a null value when reading the cookie on page A and having a default value for the background-color should the cookie's value be null. The way this particular cookie unit is set up makes that fairly easy to do.

codeexploiter
01-15-2007, 02:29 PM
Thanks John I haven't thought of using cookies and it suited simply great for my purpose.

I was working on some prototype developing so the tools that I have for development (can't go for Server-side coding in this case) mainly consists of Client-side (JavaScript, CSS & (X)Html).