Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8810229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:04:47+00:00 2026-06-14T03:04:47+00:00

I have a bit of a long function for uploading photos using hidden iFrames,

  • 0

I have a bit of a long function for uploading photos using hidden iFrames, it works great and everything, the thing is it’s a lot of messy code, and I would like to make a clean function that only has a few rows or such for making it easier and less code to work with.

function fileUpload(form, action_url)
{
// Create the iframe...
var iframe = document.createElement("iframe");
iframe.setAttribute("id","upload_iframe");
iframe.setAttribute("name","upload_iframe");
iframe.setAttribute("width","0");
iframe.setAttribute("height","0");
iframe.setAttribute("border","0");
iframe.setAttribute("style","width: 0; height: 0; border: none;");

// Add to document...
form.parentNode.appendChild(iframe);
window.frames['upload_iframe'].name="upload_iframe";

iframeId = document.getElementById("upload_iframe");

// Add event...
var eventHandler = function()  {

if (iframeId.detachEvent)
iframeId.detachEvent("onload", eventHandler);
else
iframeId.removeEventListener("load", eventHandler, false);

// Message from server...
if (iframeId.contentDocument) {
content = iframeId.contentDocument.body.innerHTML;
} else if (iframeId.contentWindow) {
content = iframeId.contentWindow.document.body.innerHTML;
} else if (iframeId.document) {
content = iframeId.document.body.innerHTML;
}
if(content)
{
/* THIS CODE SHOULD BE DEFINED IN NEW FUNCTION, AND PLACED HER AUTOMATICALLY- onSuccess()
$('img.profile-picture').attr("src","photos/"+content+"_200.jpg");
$('.post-photo'+cookie('login')).attr("src","photos/"+content+"_55.jpg");
$(".add-photo-loading").fadeOut("fast");
*/
}
else
{
/*THIS SHOULD ALSO BE DEFINED IN THE NEW FUNCTION - onError()
$(".add-photo-loading").html("Invalid Filetype");
$(".add-photo-loading").attr("class","upload-error");
*/
}
// Del the iframe...
setTimeout('iframeId.parentNode.removeChild(iframeId)', 250);
}

if (iframeId.addEventListener)
iframeId.addEventListener("load", eventHandler, true);
if (iframeId.attachEvent)
iframeId.attachEvent("onload", eventHandler);

// Set properties of form...
form.setAttribute("target","upload_iframe");
form.setAttribute("action", action_url);
form.setAttribute("method","post");
form.setAttribute("enctype","multipart/form-data");
form.setAttribute("encoding","multipart/form-data");

// Submit the form...
form.submit();
/*THIS SHOULD BE FIRED IMMEDIATELY WHEN THIS FUNCTION IS CALLED BUT THIS CODE SHOULD ALSO BE FIRED ELSEWHERE 
$(".upload-error").attr("class","add-photo-loading");
$(".add-photo-loading").html("Uploading...");
$(".add-photo-loading").css({"display":"block"});
*/
}

Okay, so there are a few lines of code in here that should be defined in the new function and I have /**/ commented around the blocks of code, with the action that is for that block.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T03:04:48+00:00Added an answer on June 14, 2026 at 3:04 am

    Here you go:

    function fileUpload(a, b) {
    var c = document.createElement("iframe");
    c.setAttribute("id", "upload_iframe"), c.setAttribute("name", "upload_iframe"), c.setAttribute("width", "0"), c.setAttribute("height", "0"), c.setAttribute("border", "0"), c.setAttribute("style", "width: 0; height: 0; border: none;"), a.parentNode.appendChild(c), window.frames.upload_iframe.name = "upload_iframe", iframeId = document.getElementById("upload_iframe");
    var d = function () {
        iframeId.detachEvent ? iframeId.detachEvent("onload", d) : iframeId.removeEventListener("load", d, !1), iframeId.contentDocument ? content = iframeId.contentDocument.body.innerHTML : iframeId.contentWindow ? content = iframeId.contentWindow.document.body.innerHTML : iframeId.document && (content = iframeId.document.body.innerHTML), setTimeout("iframeId.parentNode.removeChild(iframeId)", 250)
    };
    iframeId.addEventListener && iframeId.addEventListener("load", d, !0), iframeId.attachEvent && iframeId.attachEvent("onload", d), a.setAttribute("target", "upload_iframe"), a.setAttribute("action", b), a.setAttribute("method", "post"), a.setAttribute("enctype", "multipart/form-data"), a.setAttribute("encoding", "multipart/form-data"), a.submit()
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bit field consisting of 64 bits: long bitfield = 0; I
This is a bit of a long shot as I don't have access to
I have a question regarding how initialization vector works on cryptography. I have bit
On my little-endian z80-esque processor I have a 32-bit long int msk = 0xFFFFFF00
Suppose I have a long javascript function such as function test() { var x;
I have the following function in Ruby that decrypts a bit of data: def
I have a problem while using the printf function to print values of type
I have a bit of javascript/jquery code that takes a long string, and sends
All, I have the following bit of code: function addPoints() { newpoints[0] = new
i have a c function which returns a long double . i'd like to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.