我正在将Joomla 1.5组件转换为J2.5我动态上传文件。 iframe填充了一个表单来执行此操作,iframe有一个内部iframe来设置表单的目标。在收到JSON答案后,我使用内部iframe的onload
上的函数来擦除iframe并显示上传的图像(使用父页面的元素)。一切都在J1.5上运行得很好,但是在J2.5上我收到了一个joomla.json
文件要下载,好像表单没有使用目标。
在outter iframe上显示表单的功能是:
function showUploadImage(evt) {
if (!document.getElementById("uploadIFrame")) {
return false;
}
var frame = document.getElementById("uploadIFrame");
var doc = frame.contentDocument;
var page;
page = "\
<html> \
<head> \
<link rel='stylesheet' href='<?php echo JRoute::_(JURI::base().'/components/com_tutorial/css/base.css',false); ?>' type='text/css' /> \
<link rel='stylesheet' href='<?php echo JRoute::_(JURI::base().'components/com_tutorial/css/upframe.css',false); ?>' type='text/css' /> \
</head> \
<body>";
page += ' \
<div id="waitimage"></div> \
<form id="fileUploadForm" method="post" enctype="multipart/form-data" action="<?php echo JRoute::_('index.php?option=com_tutorial&view=edittutorial&task=savetutimage&tmpl=json&format=json&tutId='.$this->tutId); ?>" target="uploadTarget"> \
<label class="title" for="images"><?php echo JText::_("UPLOAD IMAGE"); ?></label> \
<div class="separator25"></div> \
<div id="pageimages"> \
<div id="newimgfields"> \
<div class="controw"> \
<label class="title" for="image"><?php echo JText::_('SELECT_FILE'); ?></label><input size="35" id="image" type="file" name="image" /> \
</div> \
<div class="controw"> \
<input type="submit" onclick="document.getElementById(\'waitimage\').innerHTML=\'<div class = "mooloader"></div>\';" value="<?php echo JText::_('UPLOAD_IMAGE'); ?>" /> \
</div> \
</div> \
</div> \
</form> \
<iframe id="uploadTarget" name="uploadTarget" src="" style="width:0;height:0;border:0px solid #fff;"></iframe> \
';
page += "</body></html>";
// now write out the new contents
if (doc == undefined || doc == null)
doc = frame.contentWindow.document;
doc.open();
doc.write(page);
doc.close();
doc.getElementById("uploadTarget").onload = uploadDone;
}
在“onload”上执行的功能是:
function uploadDone() {
var frame = document.getElementById("uploadIFrame");
var doc = frame.contentDocument;
var innerFrame = doc.getElementById("uploadTarget");
var ret = innerFrame.contentDocument.getElementsByTagName("body")[0].innerHTML;
var data = eval("(" + JSON.decode(ret) + ")");
//var data = eval("("+ret+")");
if (data=="0"){
alert("<?php echo JText::_('ERROR_SAVE_IMAGE'); ?>");
}
else if (data=="") {
}
else {
var upImage = new Element('img',{
'class':'tutmainthumb',
'id':'tutThumb',
'src':'components/com_tutorial/helpers/image.php?img='+data
});
upImage.inject('tutImage','top');
$('uploadIFrame').dispose();
}
}