jpnet
26 Mar 2009, 11:34 AM
I'm trying to get an onload event to fire on an Iframe. The code works as expected in HTML.
<html>
<head><title>test</title></head>
<body>
<script type="text/javascript">
ifrm = document.createElement("iframe");
ifrm.setAttribute("src", "http://myserver.com/mysuperlargefile.pdf");
ifrm.style.width.value = "100px";
ifrm.style.height.value = "100px";
ifrm.onload = function(){ alert('hi'); };
document.body.appendChild(ifrm);
</script>
</body>
</html>
You can copy and paste that into an html file and run it on your desktop. The Javascript alert is fired when the PDF is done loading. Now when I paste this same code into in a JSNI method the Javascript alert is not fired, however the PDF does load. Here is the JSNI code:
public native void createIFrame(String url) /*-{
ifrm = document.createElement("iframe");
ifrm.setAttribute("src", "http://myserver.com/mysuperlargefile.pdf");
ifrm.style.width.value = "100px";
ifrm.style.height.value = "100px";
ifrm.onload = function(){ alert('hi'); };
document.body.appendChild(ifrm);
}-*/;
Any thoughts on why the Javascript alert is not being fired when using the JSNI method?? Why does it work in a regular HTML page but not in JSNI?
This one has me stumped.
Thanks for your help.
-JP
<html>
<head><title>test</title></head>
<body>
<script type="text/javascript">
ifrm = document.createElement("iframe");
ifrm.setAttribute("src", "http://myserver.com/mysuperlargefile.pdf");
ifrm.style.width.value = "100px";
ifrm.style.height.value = "100px";
ifrm.onload = function(){ alert('hi'); };
document.body.appendChild(ifrm);
</script>
</body>
</html>
You can copy and paste that into an html file and run it on your desktop. The Javascript alert is fired when the PDF is done loading. Now when I paste this same code into in a JSNI method the Javascript alert is not fired, however the PDF does load. Here is the JSNI code:
public native void createIFrame(String url) /*-{
ifrm = document.createElement("iframe");
ifrm.setAttribute("src", "http://myserver.com/mysuperlargefile.pdf");
ifrm.style.width.value = "100px";
ifrm.style.height.value = "100px";
ifrm.onload = function(){ alert('hi'); };
document.body.appendChild(ifrm);
}-*/;
Any thoughts on why the Javascript alert is not being fired when using the JSNI method?? Why does it work in a regular HTML page but not in JSNI?
This one has me stumped.
Thanks for your help.
-JP