...

View Full Version : Script crashing browser...



Jon W
06-08-2010, 08:34 PM
Hello all. I'm working on a photo upload script. All works well until I added a simple script to get the document body innerHTML so that I could report back to the user if there was any errors or not. So...




addEvent($('uploaderIframe'),"load",showLoad);
}

var showLoad = function() {
removeEvent($('uploaderIframe'),"load",showLoad);
$('uploaderIframe').src="javascript:window.parent.document.getElementById('uploadInfo').innerHTML = document.body.innerHTML;";
}
}


It seems that whenever I try to change src of the iframe it crashes. Not to sure why, as I've seen this be done on other Ajax like Photo upload scripts. Can I get some help with this please...


Here's the full script:


function addEvent(obj, evType, fn){
if(obj.addEventListener)
obj.addEventListener(evType, fn, true)
if(obj.attachEvent)
obj.attachEvent("on"+evType, fn)
}

function removeEvent(obj, type, fn){
if(obj.detachEvent){
obj.detachEvent('on'+type, fn);
}else{
obj.removeEventListener(type, fn, false);
}
}

function ajaxPhotoUploader() {
document.getElementById('file_upload_form').onsubmit=function() {
if($('uploaderIframe')) {
document.getElementById('file_upload_form').removeChild(document.getElementById('uploaderIframe'));
}
$('uploadInfo').innerHTML = '<img src="./images/ajax-loader.gif" />';
if(window.ActiveXObject) {
var iframe = document.createElement("<iframe id=\"uploaderIframe\" name=\"uploaderIframe\" src=\"./uploadto.php\" style=\"width:200px;height:200px;\">");
}
else {
var iframe = document.createElement("iframe");
iframe.setAttribute("name","uploaderIframe");
iframe.setAttribute("src","./uploadto.php");
iframe.setAttribute("id","uploaderIframe");

}
document.getElementById('file_upload_form').appendChild(iframe);
document.getElementById('file_upload_form').target = 'uploaderIframe'; //'uploaderIframe' is the name of the iframe
addEvent($('uploaderIframe'),"load",showLoad);
}

var showLoad = function() {
removeEvent($('uploaderIframe'),"load",showLoad);
$('uploaderIframe').src="javascript:window.parent.document.getElementById('uploadInfo').innerHTML = document.body.innerHTML;";
}
}


Thanks,
Jon W

tomws
06-08-2010, 08:51 PM
You're using Firebug to check Javascript errors, right? What's it saying?

Jon W
06-08-2010, 09:03 PM
Nope, I'm not using firebug to check for errors. Never thought about to be honest. Firefox isn't the one that is crashing really anyways. Google Chrome is the only one that seems to be crashing.

Edit:

However it is messing up. It seems to be refreshing the iframe none. So it's almost as if it gets stuck in a loop.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum