views:

407

answers:

3

I want to execute javascript code inside of an iframe as soon as the rendering begins, not when the document is loaded. The purpose is that i want to modify javascript behavior inside of the frame that is executed inside of an inline script block. The onload-event would execute after the inline script which would be too late. How to execute javascript as soon as the html starts to load?

+2  A: 

You can't alter anything inside of an iframe which is not in your domain, assuming you are trying to get rid of the javascript code in the yahoo iframe from your other post.

meder
I just want the openid to be displayed inside of an iframe for the users convenience. I am not some kind of fraudster...
usr
To OpenID, you are indistinguishable from a fraudster. How could OpenID offer any kind of security if you could just cross-site-script into its login form and subvert it?
bobince
This is true. I think i have to give up this method.
usr
A: 

Instead of putting the code in onload, just place it in the script. For example, instead of

<script>
  function doStuff(){
    // ...
  }
</script>
<!-- snip -->
<body onload="doStuff();">

you should just do this:

<script>
  function doStuff(){
    // ...
  }
  doStuff();
</script>
<!-- snip -->
<body>
MiffTheFox
+1  A: 

You can put the script inline, but be very careful with this. If the page is not fully loaded and you attempt to access the DOM, you could run into exceptions. In general, I don't really recommend that you inline script. It's better to control the execution flow yourself rather than rely on the behaviour of the browser. If possible, it might be better to look for ways to move your inline script into functions that allow you to sequence the calls.

John Cavan
Unfortunately i do not own the frame code.
usr