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?
views:
407answers:
3
+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
2009-09-27 22:48:58
I just want the openid to be displayed inside of an iframe for the users convenience. I am not some kind of fraudster...
usr
2009-09-27 23:01:45
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
2009-09-28 01:36:51
This is true. I think i have to give up this method.
usr
2009-09-28 09:16:34
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
2009-09-27 22:49:57
+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
2009-09-28 01:10:47