Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > JavaScript: Общие вопросы > Фреймы: передача двоичных данных


Автор: Alca 8.10.2008, 08:46
Фреймы: передача двоичных данных? Как релизовать? Подскажите.

Автор: Itsys 8.10.2008, 16:12
Я пользуюсь следующим:
upload.js:
Код

function createIFrame() {
  var id = 'f' + Math.floor(Math.random() * 99999);
  var div = document.createElement('div');
  div.innerHTML = '<iframe style="display:none" src="about:blank" id="'+id+'" name="'+id+'" onload="sendComplete(\''+id+'\')"></iframe>';
  document.body.appendChild(div);
  return document.getElementById(id);
}

function sendForm(form, url, func, arg) {
  if (!document.createElement) return; // not supported
  if (typeof(form)=="string") form=document.getElementById(form);
  var frame=createIFrame();
  frame.onSendComplete = function() { func(arg, getIFrameXML(frame)); };
  form.setAttribute('target', frame.id);
  form.setAttribute('action', url);
  form.submit();
}

function sendComplete(id) {
  var iframe=document.getElementById(id);
  if (iframe.onSendComplete && typeof(iframe.onSendComplete) == 'function') iframe.onSendComplete();
}

function getIFrameXML(iframe) {
  var doc=iframe.contentDocument;
  if (!doc && iframe.contentWindow) doc=iframe.contentWindow.document;
  if (!doc) doc=window.frames[iframe.id].document;
  if (!doc) return null;
  if (doc.location=="about:blank") return null;
  if (doc.XMLDocument) doc=doc.XMLDocument;
  iframe.removeNode(true);
  return doc;
}


Код

<script>
  function uploadComplete(element, doc) {
//
...
}
</script>
                            <form id="ajaxUploadForm" method="post" enctype="multipart/form-data" onsubmit="sendForm(this,'[addr]',uploadComplete,'debug'); return false;">
                                Файл: <input type="file" name="Image" size="50"><input type="submit" value="Загрузить">
                            </form>


Автор: Alca 8.10.2008, 17:57
Itsys, спасибо попробую, +1
Нарыл статейку:
http://javascript.ru/ajax/transport/iframe

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)