How to get innerHTML of an iframe with the latest browser versions like IE11, Chrome 71, Firefox 62(Quantum)












1















I am using IE11, Chrome 71 and Firefox 62(Quantum) browsers. I am just experimenting with iframe to upload the file(it's not a cross domain). The same code was working fine with IE7 earlier.We are making our project a browser agnostic now. I just want to know what is the best way to get innerHTML of the iframe with latest browsers. I have tried with the following approaches, but nothing worked for me.



1)



iframeId = document.getElementById("upload_iframe");
content = iframeId.contentDocument.body.innerHTML;


2) $('#iframeId ').contents().find('body').innerHTML



3) $('#iframeId ').contents().find('body').html();



4)



iframeId = document.getElementById("upload_iframe");
iframeId.contentWindow.document.body.innerHTML


5)



iframeId = document.getElementById("upload_iframe");
iframeId.document.body.innerHTML


Any help is much apprecited.










share|improve this question





























    1















    I am using IE11, Chrome 71 and Firefox 62(Quantum) browsers. I am just experimenting with iframe to upload the file(it's not a cross domain). The same code was working fine with IE7 earlier.We are making our project a browser agnostic now. I just want to know what is the best way to get innerHTML of the iframe with latest browsers. I have tried with the following approaches, but nothing worked for me.



    1)



    iframeId = document.getElementById("upload_iframe");
    content = iframeId.contentDocument.body.innerHTML;


    2) $('#iframeId ').contents().find('body').innerHTML



    3) $('#iframeId ').contents().find('body').html();



    4)



    iframeId = document.getElementById("upload_iframe");
    iframeId.contentWindow.document.body.innerHTML


    5)



    iframeId = document.getElementById("upload_iframe");
    iframeId.document.body.innerHTML


    Any help is much apprecited.










    share|improve this question



























      1












      1








      1








      I am using IE11, Chrome 71 and Firefox 62(Quantum) browsers. I am just experimenting with iframe to upload the file(it's not a cross domain). The same code was working fine with IE7 earlier.We are making our project a browser agnostic now. I just want to know what is the best way to get innerHTML of the iframe with latest browsers. I have tried with the following approaches, but nothing worked for me.



      1)



      iframeId = document.getElementById("upload_iframe");
      content = iframeId.contentDocument.body.innerHTML;


      2) $('#iframeId ').contents().find('body').innerHTML



      3) $('#iframeId ').contents().find('body').html();



      4)



      iframeId = document.getElementById("upload_iframe");
      iframeId.contentWindow.document.body.innerHTML


      5)



      iframeId = document.getElementById("upload_iframe");
      iframeId.document.body.innerHTML


      Any help is much apprecited.










      share|improve this question
















      I am using IE11, Chrome 71 and Firefox 62(Quantum) browsers. I am just experimenting with iframe to upload the file(it's not a cross domain). The same code was working fine with IE7 earlier.We are making our project a browser agnostic now. I just want to know what is the best way to get innerHTML of the iframe with latest browsers. I have tried with the following approaches, but nothing worked for me.



      1)



      iframeId = document.getElementById("upload_iframe");
      content = iframeId.contentDocument.body.innerHTML;


      2) $('#iframeId ').contents().find('body').innerHTML



      3) $('#iframeId ').contents().find('body').html();



      4)



      iframeId = document.getElementById("upload_iframe");
      iframeId.contentWindow.document.body.innerHTML


      5)



      iframeId = document.getElementById("upload_iframe");
      iframeId.document.body.innerHTML


      Any help is much apprecited.







      javascript jquery html iframe






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 21 '18 at 7:10







      Ashok.N

















      asked Nov 21 '18 at 7:04









      Ashok.NAshok.N

      56531238




      56531238
























          1 Answer
          1






          active

          oldest

          votes


















          0














          did you try the following?



          window.frames['upload_iframe'].document.body.innerHTML 


          (for IE)



          window.frames[0].document.body.innerHTML


          (for Firefox and Chrome)






          share|improve this answer
























          • ,Thanks for the response. But your suggestion is not working for me. I am getting Uncaught TypeError: Cannot read property 'innerHTML' of null because window.frames[0].document.body itself is becoming null . Any other thoughts please..

            – Ashok.N
            Nov 21 '18 at 8:14













          • try changing the 0 to your frame id window.frames['upload_iframe'].document.body.innerHTML

            – Mustafa Anas
            Nov 21 '18 at 8:20













          • still the same error after changing it to window.frames['upload_iframe'].document.body.innerHTML

            – Ashok.N
            Nov 21 '18 at 8:23











          • if not, my last suggestion would be to try using contentDocument property [w3schools.com/jsref/prop_frame_contentdocument.asp]

            – Mustafa Anas
            Nov 21 '18 at 8:25











          • Still not working. iframeId.body is coming as undefined, not sure what to do after this.

            – Ashok.N
            Nov 21 '18 at 9:02











          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%2f53406832%2fhow-to-get-innerhtml-of-an-iframe-with-the-latest-browser-versions-like-ie11-ch%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          did you try the following?



          window.frames['upload_iframe'].document.body.innerHTML 


          (for IE)



          window.frames[0].document.body.innerHTML


          (for Firefox and Chrome)






          share|improve this answer
























          • ,Thanks for the response. But your suggestion is not working for me. I am getting Uncaught TypeError: Cannot read property 'innerHTML' of null because window.frames[0].document.body itself is becoming null . Any other thoughts please..

            – Ashok.N
            Nov 21 '18 at 8:14













          • try changing the 0 to your frame id window.frames['upload_iframe'].document.body.innerHTML

            – Mustafa Anas
            Nov 21 '18 at 8:20













          • still the same error after changing it to window.frames['upload_iframe'].document.body.innerHTML

            – Ashok.N
            Nov 21 '18 at 8:23











          • if not, my last suggestion would be to try using contentDocument property [w3schools.com/jsref/prop_frame_contentdocument.asp]

            – Mustafa Anas
            Nov 21 '18 at 8:25











          • Still not working. iframeId.body is coming as undefined, not sure what to do after this.

            – Ashok.N
            Nov 21 '18 at 9:02
















          0














          did you try the following?



          window.frames['upload_iframe'].document.body.innerHTML 


          (for IE)



          window.frames[0].document.body.innerHTML


          (for Firefox and Chrome)






          share|improve this answer
























          • ,Thanks for the response. But your suggestion is not working for me. I am getting Uncaught TypeError: Cannot read property 'innerHTML' of null because window.frames[0].document.body itself is becoming null . Any other thoughts please..

            – Ashok.N
            Nov 21 '18 at 8:14













          • try changing the 0 to your frame id window.frames['upload_iframe'].document.body.innerHTML

            – Mustafa Anas
            Nov 21 '18 at 8:20













          • still the same error after changing it to window.frames['upload_iframe'].document.body.innerHTML

            – Ashok.N
            Nov 21 '18 at 8:23











          • if not, my last suggestion would be to try using contentDocument property [w3schools.com/jsref/prop_frame_contentdocument.asp]

            – Mustafa Anas
            Nov 21 '18 at 8:25











          • Still not working. iframeId.body is coming as undefined, not sure what to do after this.

            – Ashok.N
            Nov 21 '18 at 9:02














          0












          0








          0







          did you try the following?



          window.frames['upload_iframe'].document.body.innerHTML 


          (for IE)



          window.frames[0].document.body.innerHTML


          (for Firefox and Chrome)






          share|improve this answer













          did you try the following?



          window.frames['upload_iframe'].document.body.innerHTML 


          (for IE)



          window.frames[0].document.body.innerHTML


          (for Firefox and Chrome)







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 21 '18 at 7:33









          Mustafa AnasMustafa Anas

          148




          148













          • ,Thanks for the response. But your suggestion is not working for me. I am getting Uncaught TypeError: Cannot read property 'innerHTML' of null because window.frames[0].document.body itself is becoming null . Any other thoughts please..

            – Ashok.N
            Nov 21 '18 at 8:14













          • try changing the 0 to your frame id window.frames['upload_iframe'].document.body.innerHTML

            – Mustafa Anas
            Nov 21 '18 at 8:20













          • still the same error after changing it to window.frames['upload_iframe'].document.body.innerHTML

            – Ashok.N
            Nov 21 '18 at 8:23











          • if not, my last suggestion would be to try using contentDocument property [w3schools.com/jsref/prop_frame_contentdocument.asp]

            – Mustafa Anas
            Nov 21 '18 at 8:25











          • Still not working. iframeId.body is coming as undefined, not sure what to do after this.

            – Ashok.N
            Nov 21 '18 at 9:02



















          • ,Thanks for the response. But your suggestion is not working for me. I am getting Uncaught TypeError: Cannot read property 'innerHTML' of null because window.frames[0].document.body itself is becoming null . Any other thoughts please..

            – Ashok.N
            Nov 21 '18 at 8:14













          • try changing the 0 to your frame id window.frames['upload_iframe'].document.body.innerHTML

            – Mustafa Anas
            Nov 21 '18 at 8:20













          • still the same error after changing it to window.frames['upload_iframe'].document.body.innerHTML

            – Ashok.N
            Nov 21 '18 at 8:23











          • if not, my last suggestion would be to try using contentDocument property [w3schools.com/jsref/prop_frame_contentdocument.asp]

            – Mustafa Anas
            Nov 21 '18 at 8:25











          • Still not working. iframeId.body is coming as undefined, not sure what to do after this.

            – Ashok.N
            Nov 21 '18 at 9:02

















          ,Thanks for the response. But your suggestion is not working for me. I am getting Uncaught TypeError: Cannot read property 'innerHTML' of null because window.frames[0].document.body itself is becoming null . Any other thoughts please..

          – Ashok.N
          Nov 21 '18 at 8:14







          ,Thanks for the response. But your suggestion is not working for me. I am getting Uncaught TypeError: Cannot read property 'innerHTML' of null because window.frames[0].document.body itself is becoming null . Any other thoughts please..

          – Ashok.N
          Nov 21 '18 at 8:14















          try changing the 0 to your frame id window.frames['upload_iframe'].document.body.innerHTML

          – Mustafa Anas
          Nov 21 '18 at 8:20







          try changing the 0 to your frame id window.frames['upload_iframe'].document.body.innerHTML

          – Mustafa Anas
          Nov 21 '18 at 8:20















          still the same error after changing it to window.frames['upload_iframe'].document.body.innerHTML

          – Ashok.N
          Nov 21 '18 at 8:23





          still the same error after changing it to window.frames['upload_iframe'].document.body.innerHTML

          – Ashok.N
          Nov 21 '18 at 8:23













          if not, my last suggestion would be to try using contentDocument property [w3schools.com/jsref/prop_frame_contentdocument.asp]

          – Mustafa Anas
          Nov 21 '18 at 8:25





          if not, my last suggestion would be to try using contentDocument property [w3schools.com/jsref/prop_frame_contentdocument.asp]

          – Mustafa Anas
          Nov 21 '18 at 8:25













          Still not working. iframeId.body is coming as undefined, not sure what to do after this.

          – Ashok.N
          Nov 21 '18 at 9:02





          Still not working. iframeId.body is coming as undefined, not sure what to do after this.

          – Ashok.N
          Nov 21 '18 at 9:02




















          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%2f53406832%2fhow-to-get-innerhtml-of-an-iframe-with-the-latest-browser-versions-like-ie11-ch%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







          這個網誌中的熱門文章

          Xamarin.form Move up view when keyboard appear

          Post-Redirect-Get with Spring WebFlux and Thymeleaf

          Anylogic : not able to use stopDelay()