Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Brisbane, Australia
    Posts
    181
    Thanks
    1
    Thanked 0 Times in 0 Posts

    iFrame onload event

    When i execute the following code:

    Code:
    document.getElementById ("iframeobj").contentWindow.onload = new function () {
      document.getElementById ("iframeobj").contentWindow.applycommand ();
    }

    the command is executed, but the result is rolledback after the frame has loaded. does anyone have any ideas? i'm aware of the restrictions that the iframe property has, but i don't think this is affected by this, is it?


    Using: MIRCOSOFT INTERNET EXPLORER 6.0
    O/S: Microsoft Windows XP (SP1)


    I've attached two files to show an example, but i've renamed them to .txt. just remove the extension and it should work.
    Last edited by mr_ego; 01-15-2006 at 02:27 AM.
    -mR_eGo
    _______________________
    Programming since
    3 years old.

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I do not think you are using contentWindow properly...
    When I run your script I get an unspecified error #84...

    http://msdn.microsoft.com/library/de...tentwindow.asp

    .....Willy

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Brisbane, Australia
    Posts
    181
    Thanks
    1
    Thanked 0 Times in 0 Posts
    so how do i force an iFrame to run a command remotely (keeping in mind the files are on the same domain)
    -mR_eGo
    _______________________
    Programming since
    3 years old.

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    <iframe name="panel[frame]" src="test2.html" onload="this.contentWindow.applycommand()"></iframe>
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    Brisbane, Australia
    Posts
    181
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Well, my iFrame isn't generated in html, it's generated through a document.createElement command.
    -mR_eGo
    _______________________
    Programming since
    3 years old.

  • #6
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, create the onload attribute when you create the element...

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Location
    Brisbane, Australia
    Posts
    181
    Thanks
    1
    Thanked 0 Times in 0 Posts
    doesn't work

    Code:
    	function createTheElement () {
    		var iframe = document.createElement ("IFRAME");
    		iframe.frameBorder = 1;
    		iframe.width = 400;
    		iframe.height = 400;
    		iframe.src = "test.html";
    		iframe.setAttribute ("id", "testframe");
    		
    		iframe.onload = new function () {
    			alert (document.getElementById ("testframe").style);
    		}
    		
    		document.getElementById ("testit").innerHTML = iframe.outerHTML;
    	}
    		
    	window.onload = new function () {
    		createTheElement ();
    	}
    -mR_eGo
    _______________________
    Programming since
    3 years old.

  • #8
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What doesn't work?? Creating the onload attribute and firing the alert certainly does, but what is this??

    alert (document.getElementById ("testframe").style);

    .....Willy

  • #9
    Regular Coder
    Join Date
    Jun 2002
    Location
    Brisbane, Australia
    Posts
    181
    Thanks
    1
    Thanked 0 Times in 0 Posts
    can someone please upload an example?!
    -mR_eGo
    _______________________
    Programming since
    3 years old.

  • #10
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    IE only:
    Code:
    function createTheElement () {
    		var iframe = document.createElement ('<iframe onload="this.contentWindow.applycommand()"></iframe>');
    		iframe.frameBorder = 1;
    		iframe.width = 400;
    		iframe.height = 400;
    		iframe.src = "test.html";
    		iframe.setAttribute ("id", "testframe");
    		document.getElementById ("testit").innerHTML = iframe.outerHTML;
    	}
    		
    	window.onload = function () {
    		createTheElement ();
    	}
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #11
    Regular Coder
    Join Date
    Jun 2002
    Location
    Brisbane, Australia
    Posts
    181
    Thanks
    1
    Thanked 0 Times in 0 Posts
    that isn't really good w3c standard ... besides it has to work for FireFox aswell.
    -mR_eGo
    _______________________
    Programming since
    3 years old.

  • #12
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    I assumed you want it to work with IE only because you use outerHTML. Use appendChild instead of innerHTML/outerHTML.

    Try this:
    Code:
        function createTheElement() {
            var iframe;
            if (document.all){
    		iframe = document.createElement('<iframe onload="alert(document.getElementById (\'testframe\'))"></iframe>');
    	}
            else if (document.getElementById) {
    		iframe = document.createElement('iframe');
    		iframe.onload=function(){alert(document.getElementById('testframe'))};
    	}
            if (!iframe) return;        
            iframe.frameBorder = 1;
            iframe.width = 400;
            iframe.height = 400;
            iframe.src = "test2.html"
            iframe.setAttribute ("id", "testframe");
            document.getElementById ("testit").appendChild(iframe);
        }
            
        window.onload = function () {
            createTheElement ();
        }
    Last edited by glenngv; 01-03-2005 at 03:18 PM.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #13
    Regular Coder
    Join Date
    Jun 2002
    Location
    Brisbane, Australia
    Posts
    181
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Ahh i'm such a dimwit! Thanks for that glenngv. Is it possible that you can get the help member of the millenium award?
    -mR_eGo
    _______________________
    Programming since
    3 years old.

  • #14
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Quote Originally Posted by mr_ego
    Ahh i'm such a dimwit! Thanks for that glenngv. Is it possible that you can get the help member of the millenium award?
    There's a new Nominate a helpful member thread.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •