Forum Moderators: open

Message Too Old, No Replies

IFrame loading PHP page doesn't work in Firefox

         

stillriverweb

5:33 pm on May 5, 2006 (gmt 0)

10+ Year Member



Ok, what I'm trying to do is use JavaScript to load a PHP page in a IFrame which writes to a MYSQL DB. The code I am currently using works with IE but does not work with Firefox (doesn't write to the DB). But here's the weird thing that I can't figure out, when I add an alert after setting the IFrame url, it works in Firefox.

Here's the code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN">
<html>
<head>
<title>Still River Web Solutions</title>
<script language="javascript">
function loadIframe(data) {
var url = 'http://www.stillriverweb.com/test/write.php?data=' + data;
window.frames['ifrm'].location = url;
//alert('test');
return true;
}
</script>
</head>
<body>
<form onsubmit="return loadIframe('test');">
<input type="submit" value="Submit">
</form>
<iframe id="ifrm" name="ifrm" scrolling="no" width="0" height="0" frameborder="0"></iframe>
</body>
</html>

I've tried everything I can think of. Any ideas would be appreciated.

Fotiman

6:29 pm on May 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I would suspect that your frame document hasn't finished loading before the form submit happens. In other words:

window.frames['ifrm'].location = url;

is an asynchronous call. That is, your script will not stop executing here... it will continue on, even if the document has not finished loading in 'ifrm'.

stillriverweb

7:12 pm on May 5, 2006 (gmt 0)

10+ Year Member



Thanks Fotiman, I figured it was something like that. Here's my solution using a webbug instead of an IFrame which seems to work well:

function loadIframe(data) {
write = new Image();
url = 'http://www.jhnsyn.com/referraltracking/contact.php?data=' + data;
write.src = url;
while (!write.complete) {}
return true;
}

kaled

7:33 pm on May 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Could you use the <iframe onload> event?

Kaled.

Fotiman

9:02 pm on May 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Note that this:

while (!write.complete) {}
return true;

is a potential performance killer.