homepage Welcome to WebmasterWorld Guest from 54.227.56.174
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
frame access issue
sivaks75




msg:4339249
 9:54 pm on Jul 13, 2011 (gmt 0)

Hi,

I have a webpage which is splitted into 2 frames. Frame 1(page1.jsp) loads the information in frame 2(page2.jsp) onclick of a link. Later frame 2 redirected to different page(page3.jsp) based on business requirement.

Now if i click the same link on frame 1(page 1) while page3.jsp is on frame 2, I am having issues accessing the page2 elements in frame 2.

Here is the sample of piece of code.
1. First loading the page2.jsp in frame 2
2. Accessing page 2 elements and assigning value

Actually what is happening is that, it loads the page2 successfully without any issues. But the value is not getting set as given in the second statement. If I try to put some alert statement in the end, I too see the value, but once the javascript function is executed, the value disappears in second page.

function loadPage2(){
window.top.frames["frame2"].location.href="page2.jsp";
window.top.frames["frame2"].document.getElementById("name").innerHTML = "TestService";
}

Any help appreciated.

Regards,
Siva

 

daveVk




msg:4339787
 1:52 am on Jul 15, 2011 (gmt 0)

This is probably an issue of timing

window.top.frames["frame2"].location.href="page2.jsp";

will initiate the loading of frame2, but does not delay the execution of the next statement until loading is complete.

adding an alert between the two statements will change the timing and affirm the problem.

The second statement should be moved to a onload handler.

Welcome to forum

JAB Creations




msg:4339789
 2:01 am on Jul 15, 2011 (gmt 0)

Hi Siva and welcome to WebmasterWorld. :)

First thing is first, don't use innerHTML, it's a proprietary Microsoft method that is not reliable, stick to using standards compliant methods (e.g. appendChild, importNode, insertBefore). To change an element's text use the following...

document.getElementById('my_element_id_here').firstChild.nodeValue = 'new text';


Secondly are the frames both on the same domain or not? If not then that may be the issue, cross-domain scripting is from what I've read riddled with security issues hence why I've also read it's extremely difficult to work with.

You may need to use the following to change the text...

parent.frame2.document.getElementById('my_element_id_here').firstChild.nodeValue = 'new text';


Also don't use very generic words such as 'border', 'id', 'name' etc for id or names of elements as you can quietly run in to resource conflicts with reserved words.

- John

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved