iframe's contentDocument body is null












0















I am using the following iframe related code for uploading the file.



  function createAttachmentRequest(form, action_url, div_id){           
document.getElementById("CreateAttachmentForm").elements["userId"].value = m_userID;
document.getElementById("CreateAttachmentForm").elements["password"].value = m_password_e;
document.getElementById("CreateAttachmentForm").elements["METHOD"].value = "POST";
document.getElementById("CreateAttachmentForm").elements["parentIds"].value = strIssueID;

// 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.indexOf('HTTP Status') !== -1){
document.getElementById("IssueFileUploadHead").innerHTML = 'There is an error. Please contact Administrator';
}else{
//get the response string and return the object id from the response string
document.getElementById("IssueFileUploadHead").innerHTML = content;
var responseString = document.getElementById("IssueFileUploadHead").innerText;
document.getElementById("IssueFileUploadHead").innerHTML = "Uploading...";
var responseTag = "<response>";
var responseEnd = "</response>";
var objId = responseString.match(new RegExp(responseTag + "(.*)" + responseEnd));

if(objId && objId.length>1){
window.parent.ModalHelper.setRetVal(objId[1]);
}
window.parent.ModalHelper.close();
}

// 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();
document.getElementById("IssueFileUploadHead").innerHTML = "Uploading...";
}


After getting the response from rest service,iframeId.contentDocument.body is becoming null. It appears that iframeId.contentDocument doesn't have the body. Any clue on what's wrong here and what can be done to make it work?
Now I have added the entire function to the question. Please take a look now.










share|improve this question

























  • Is the iframe loading from the same domain as your page? If not, this won't work for cross-domain security reasons.

    – peeebeee
    Nov 20 '18 at 15:12











  • I don't see any src for this iframe

    – charlietfl
    Nov 20 '18 at 15:13











  • @peeebeee iframe is loading from the same domain.

    – Ashok.N
    Nov 20 '18 at 15:14













  • @charlietfl, I didn't get you, Could you please elaborate?

    – Ashok.N
    Nov 20 '18 at 15:15






  • 1





    If you aren't setting src that may be part of the problem. How is content being loaded? Or how to you intend to use this iframe?

    – charlietfl
    Nov 20 '18 at 15:23


















0















I am using the following iframe related code for uploading the file.



  function createAttachmentRequest(form, action_url, div_id){           
document.getElementById("CreateAttachmentForm").elements["userId"].value = m_userID;
document.getElementById("CreateAttachmentForm").elements["password"].value = m_password_e;
document.getElementById("CreateAttachmentForm").elements["METHOD"].value = "POST";
document.getElementById("CreateAttachmentForm").elements["parentIds"].value = strIssueID;

// 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.indexOf('HTTP Status') !== -1){
document.getElementById("IssueFileUploadHead").innerHTML = 'There is an error. Please contact Administrator';
}else{
//get the response string and return the object id from the response string
document.getElementById("IssueFileUploadHead").innerHTML = content;
var responseString = document.getElementById("IssueFileUploadHead").innerText;
document.getElementById("IssueFileUploadHead").innerHTML = "Uploading...";
var responseTag = "<response>";
var responseEnd = "</response>";
var objId = responseString.match(new RegExp(responseTag + "(.*)" + responseEnd));

if(objId && objId.length>1){
window.parent.ModalHelper.setRetVal(objId[1]);
}
window.parent.ModalHelper.close();
}

// 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();
document.getElementById("IssueFileUploadHead").innerHTML = "Uploading...";
}


After getting the response from rest service,iframeId.contentDocument.body is becoming null. It appears that iframeId.contentDocument doesn't have the body. Any clue on what's wrong here and what can be done to make it work?
Now I have added the entire function to the question. Please take a look now.










share|improve this question

























  • Is the iframe loading from the same domain as your page? If not, this won't work for cross-domain security reasons.

    – peeebeee
    Nov 20 '18 at 15:12











  • I don't see any src for this iframe

    – charlietfl
    Nov 20 '18 at 15:13











  • @peeebeee iframe is loading from the same domain.

    – Ashok.N
    Nov 20 '18 at 15:14













  • @charlietfl, I didn't get you, Could you please elaborate?

    – Ashok.N
    Nov 20 '18 at 15:15






  • 1





    If you aren't setting src that may be part of the problem. How is content being loaded? Or how to you intend to use this iframe?

    – charlietfl
    Nov 20 '18 at 15:23
















0












0








0








I am using the following iframe related code for uploading the file.



  function createAttachmentRequest(form, action_url, div_id){           
document.getElementById("CreateAttachmentForm").elements["userId"].value = m_userID;
document.getElementById("CreateAttachmentForm").elements["password"].value = m_password_e;
document.getElementById("CreateAttachmentForm").elements["METHOD"].value = "POST";
document.getElementById("CreateAttachmentForm").elements["parentIds"].value = strIssueID;

// 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.indexOf('HTTP Status') !== -1){
document.getElementById("IssueFileUploadHead").innerHTML = 'There is an error. Please contact Administrator';
}else{
//get the response string and return the object id from the response string
document.getElementById("IssueFileUploadHead").innerHTML = content;
var responseString = document.getElementById("IssueFileUploadHead").innerText;
document.getElementById("IssueFileUploadHead").innerHTML = "Uploading...";
var responseTag = "<response>";
var responseEnd = "</response>";
var objId = responseString.match(new RegExp(responseTag + "(.*)" + responseEnd));

if(objId && objId.length>1){
window.parent.ModalHelper.setRetVal(objId[1]);
}
window.parent.ModalHelper.close();
}

// 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();
document.getElementById("IssueFileUploadHead").innerHTML = "Uploading...";
}


After getting the response from rest service,iframeId.contentDocument.body is becoming null. It appears that iframeId.contentDocument doesn't have the body. Any clue on what's wrong here and what can be done to make it work?
Now I have added the entire function to the question. Please take a look now.










share|improve this question
















I am using the following iframe related code for uploading the file.



  function createAttachmentRequest(form, action_url, div_id){           
document.getElementById("CreateAttachmentForm").elements["userId"].value = m_userID;
document.getElementById("CreateAttachmentForm").elements["password"].value = m_password_e;
document.getElementById("CreateAttachmentForm").elements["METHOD"].value = "POST";
document.getElementById("CreateAttachmentForm").elements["parentIds"].value = strIssueID;

// 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.indexOf('HTTP Status') !== -1){
document.getElementById("IssueFileUploadHead").innerHTML = 'There is an error. Please contact Administrator';
}else{
//get the response string and return the object id from the response string
document.getElementById("IssueFileUploadHead").innerHTML = content;
var responseString = document.getElementById("IssueFileUploadHead").innerText;
document.getElementById("IssueFileUploadHead").innerHTML = "Uploading...";
var responseTag = "<response>";
var responseEnd = "</response>";
var objId = responseString.match(new RegExp(responseTag + "(.*)" + responseEnd));

if(objId && objId.length>1){
window.parent.ModalHelper.setRetVal(objId[1]);
}
window.parent.ModalHelper.close();
}

// 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();
document.getElementById("IssueFileUploadHead").innerHTML = "Uploading...";
}


After getting the response from rest service,iframeId.contentDocument.body is becoming null. It appears that iframeId.contentDocument doesn't have the body. Any clue on what's wrong here and what can be done to make it work?
Now I have added the entire function to the question. Please take a look now.







javascript html iframe






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 15:26







Ashok.N

















asked Nov 20 '18 at 15:04









Ashok.NAshok.N

56031237




56031237













  • Is the iframe loading from the same domain as your page? If not, this won't work for cross-domain security reasons.

    – peeebeee
    Nov 20 '18 at 15:12











  • I don't see any src for this iframe

    – charlietfl
    Nov 20 '18 at 15:13











  • @peeebeee iframe is loading from the same domain.

    – Ashok.N
    Nov 20 '18 at 15:14













  • @charlietfl, I didn't get you, Could you please elaborate?

    – Ashok.N
    Nov 20 '18 at 15:15






  • 1





    If you aren't setting src that may be part of the problem. How is content being loaded? Or how to you intend to use this iframe?

    – charlietfl
    Nov 20 '18 at 15:23





















  • Is the iframe loading from the same domain as your page? If not, this won't work for cross-domain security reasons.

    – peeebeee
    Nov 20 '18 at 15:12











  • I don't see any src for this iframe

    – charlietfl
    Nov 20 '18 at 15:13











  • @peeebeee iframe is loading from the same domain.

    – Ashok.N
    Nov 20 '18 at 15:14













  • @charlietfl, I didn't get you, Could you please elaborate?

    – Ashok.N
    Nov 20 '18 at 15:15






  • 1





    If you aren't setting src that may be part of the problem. How is content being loaded? Or how to you intend to use this iframe?

    – charlietfl
    Nov 20 '18 at 15:23



















Is the iframe loading from the same domain as your page? If not, this won't work for cross-domain security reasons.

– peeebeee
Nov 20 '18 at 15:12





Is the iframe loading from the same domain as your page? If not, this won't work for cross-domain security reasons.

– peeebeee
Nov 20 '18 at 15:12













I don't see any src for this iframe

– charlietfl
Nov 20 '18 at 15:13





I don't see any src for this iframe

– charlietfl
Nov 20 '18 at 15:13













@peeebeee iframe is loading from the same domain.

– Ashok.N
Nov 20 '18 at 15:14







@peeebeee iframe is loading from the same domain.

– Ashok.N
Nov 20 '18 at 15:14















@charlietfl, I didn't get you, Could you please elaborate?

– Ashok.N
Nov 20 '18 at 15:15





@charlietfl, I didn't get you, Could you please elaborate?

– Ashok.N
Nov 20 '18 at 15:15




1




1





If you aren't setting src that may be part of the problem. How is content being loaded? Or how to you intend to use this iframe?

– charlietfl
Nov 20 '18 at 15:23







If you aren't setting src that may be part of the problem. How is content being loaded? Or how to you intend to use this iframe?

– charlietfl
Nov 20 '18 at 15:23














0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53395872%2fiframes-contentdocument-body-is-null%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53395872%2fiframes-contentdocument-body-is-null%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

How to fix TextFormField cause rebuild widget in Flutter