469,643 Members | 2,003 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,643 developers. It's quick & easy.

Dynamically setting onload event handlers across frames

392 Expert 256MB

I am trying to dynamically set an event handler across frames. I have no problems setting properties across frames doing something like

Expand|Select|Wrap|Line Numbers
  1. parent.ToolMenuFrame.location.href = 'http://www.blah blah blah.com';
But when I try to set an event handler this way, as shown below, it fails.

Expand|Select|Wrap|Line Numbers
  1. parent.ToolMenuFrame.window.document.body.onload = "alert('On Load Trigger Fired!!');";
  2. parent.ToolMenuFrame.document.body.onload = "alert('On Load Trigger Fired!!');";
  3. parent.ToolMenuFrame.body.onload = "alert('On Load Trigger Fired!!');";
  4. parent.ToolMenuFrame.window.document.body.onload = "new Function("alert('On Load Trigger Fired!!');")";
  5. parent.ToolMenuFrame.document.body.onload = "new Function("alert('On Load Trigger Fired!!');")";
  6. parent.ToolMenuFrame.body.onload = "new Function("alert('On Load Trigger Fired!!');")";
Has anyone else ever done something like this? Also the DOM docs for both IE and Gecko (Firefox, Mozilla) say I should be able to set the onload handler on the frameset tags as well. Has anyone had any luck doing this?
Nov 14 '06 #1
6 9122
1,208 Expert 1GB
the one way you didn't try
parent.ToolMenuFrame.window.onload = alert("Onload trigger fired!");
Nov 14 '06 #2
392 Expert 256MB
I have tried that one too. No luck.
Nov 14 '06 #3
392 Expert 256MB
Does any one know of a way to test if a page has completed loading with out using the onload() event handler? I have not been able to get onload() to work relably inside frames, or when setting it dynamiclly via javascript. As well as problems with it triggering while the page is still loading.

We have been able to get a working option setup using the .readyState attribute of a frame, but it only works in IE.

Does anyone have any other ideas?
Nov 14 '06 #4
392 Expert 256MB
the one way you didn't try
parent.ToolMenuFrame.window.onload = alert("Onload trigger fired!");
Ha! I tried this before with no luck, but now it is working!! It must have something with the way I was doing the quotes. Thanks.
Nov 14 '06 #5
I am also trying to achieve same kind of functionality in IE.

staying from parent or top frame's (lets say main index container frame) javascript how to call a child frame's (lets say Content frame) onload event. In turn the onload funtion in child frame calls other functions..

Assuming that, I have only one javascript file that is on the top frame.
And it have its own functions on onload event of its own.
I tried to write an onload event from top level javascript as below:

Expand|Select|Wrap|Line Numbers
  1. window.self.onload = function () {
  2.  if(checkCookieExist('uid')){
  3.      //do some
  4.   }
  5. }  //This top level onload works
  7. window.top.frames[2].onload = function () {
  8.     alert("Content loaded");
  9.     // do something
  10.   window.top.dynamicallyWriteJS("window.top.frames['ContentFrame']", 'framemodal3.js');
  11. }   //This other frame[0]  onload does not work
So, again I am trying to create an onload function in child's DOM in head section dynamically at runtime and trying to call that function all in the top level javascript only..

Expand|Select|Wrap|Line Numbers
  1. function dynamicallyLoadJS(onFrame, jsFilename){
  2.   if(onFrame){
  3. //    var htmlDoc = onFrame.document.getElementsByTagName('head').item(0);
  4.     var htmlDoc = onFrame.document.getElementsByTagName('head');
  5.   }else {
  6. //      var htmlDoc = window.top.document.getElementsByTagName('head').item(0);
  7.     var htmlDoc = window.top.document.getElementsByTagName('head');    
  8.   }
  9.    alert("dynamicallyLoadJS()  : \n frame Title = "+onFrame.document.title);
  11.   var jsEle=document.createElement('script');
  12.   jsEle.setAttribute('type','text/javascript');
  13.   jsEle.setAttribute('language', 'javascript');
  14.   jsEle.setAttribute('src', jsFilename);
  15.   htmlDoc.appendChild(jsEle);       //In IE I am getting error here : Object  oest not support this property or method.
  16.   return true;
  17. }
But I am failing..
Can't we call different onload funtions on different frames froma single javascript file ?
Please guide me..

Feb 13 '09 #6
1,208 Expert 1GB
You simply use the frame name or id for reference
Expand|Select|Wrap|Line Numbers
  1. <frame id="blah">
  2. <frame id="blah1">
  3. <frame id="blah2">
  5. <script>
  6. document.getElementById("blah1").onload = function() {
  7. /*dostuff*/
  8. }
  9. </script>
Feb 18 '09 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by relaxedrob | last post: by
20 posts views Thread by David | last post: by
2 posts views Thread by laredotornado | last post: by
6 posts views Thread by pierre.bru | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.