Welcome to WebmasterWorld Guest from 54.162.155.183

Forum Moderators: open

Message Too Old, No Replies

frame access issue

     
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
1:52 am on Jul 15, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



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
2:01 am on Jul 15, 2011 (gmt 0)

WebmasterWorld Senior Member jab_creations is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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
 

Featured Threads

Hot Threads This Week

Hot Threads This Month