Check if text selection is in header/footer





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















The Word Addin we created allows adding custom comments to text selections. Word does not allow adding comments in headers / footers. Because of that, users should get warned when text in a header/footer is selected.




  • The selection's OOXML structure for text in body and text in header is identical.

  • The Word UI itself disabled the review comments section when footer/header text is selected.

  • When dumping the text selection object to te console, none of the object fields point to the selection being in header/footer.


How can be found out programmatically that text is selected in the header/footer?



Issue: https://github.com/OfficeDev/office-js/issues/341










share|improve this question































    1















    The Word Addin we created allows adding custom comments to text selections. Word does not allow adding comments in headers / footers. Because of that, users should get warned when text in a header/footer is selected.




    • The selection's OOXML structure for text in body and text in header is identical.

    • The Word UI itself disabled the review comments section when footer/header text is selected.

    • When dumping the text selection object to te console, none of the object fields point to the selection being in header/footer.


    How can be found out programmatically that text is selected in the header/footer?



    Issue: https://github.com/OfficeDev/office-js/issues/341










    share|improve this question



























      1












      1








      1








      The Word Addin we created allows adding custom comments to text selections. Word does not allow adding comments in headers / footers. Because of that, users should get warned when text in a header/footer is selected.




      • The selection's OOXML structure for text in body and text in header is identical.

      • The Word UI itself disabled the review comments section when footer/header text is selected.

      • When dumping the text selection object to te console, none of the object fields point to the selection being in header/footer.


      How can be found out programmatically that text is selected in the header/footer?



      Issue: https://github.com/OfficeDev/office-js/issues/341










      share|improve this question
















      The Word Addin we created allows adding custom comments to text selections. Word does not allow adding comments in headers / footers. Because of that, users should get warned when text in a header/footer is selected.




      • The selection's OOXML structure for text in body and text in header is identical.

      • The Word UI itself disabled the review comments section when footer/header text is selected.

      • When dumping the text selection object to te console, none of the object fields point to the selection being in header/footer.


      How can be found out programmatically that text is selected in the header/footer?



      Issue: https://github.com/OfficeDev/office-js/issues/341







      ms-word office-js






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 3 at 12:49









      Cindy Meister

      16k102537




      16k102537










      asked Jan 3 at 8:49









      RvanlaakRvanlaak

      2,1231027




      2,1231027
























          1 Answer
          1






          active

          oldest

          votes


















          1














          You can achieve this by looking at the parentBody property of the selection range. The type property on the parentBody will reveal whether the selection is in the 'Header' or elsewhere (see documentation).



          Example



          function determineSelectionInHeader() {
          Word.run(function (context) {
          const HEADER_TYPE = "Header";

          // Retrieve and load 'type' of selection.
          var selection = context.document.getSelection();
          var parentBody = selection.parentBody;
          parentBody.load("type");

          context
          .sync()
          .then(function () {
          if (parentBody.type === HEADER_TYPE) {
          console.log("This is the header");
          }
          });
          });
          }





          share|improve this answer
























          • Perfect, parentBody.type indeed did the trick. Was not aware that headers / footers have their own body.

            – Rvanlaak
            Jan 3 at 12:57












          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%2f54018956%2fcheck-if-text-selection-is-in-header-footer%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









          1














          You can achieve this by looking at the parentBody property of the selection range. The type property on the parentBody will reveal whether the selection is in the 'Header' or elsewhere (see documentation).



          Example



          function determineSelectionInHeader() {
          Word.run(function (context) {
          const HEADER_TYPE = "Header";

          // Retrieve and load 'type' of selection.
          var selection = context.document.getSelection();
          var parentBody = selection.parentBody;
          parentBody.load("type");

          context
          .sync()
          .then(function () {
          if (parentBody.type === HEADER_TYPE) {
          console.log("This is the header");
          }
          });
          });
          }





          share|improve this answer
























          • Perfect, parentBody.type indeed did the trick. Was not aware that headers / footers have their own body.

            – Rvanlaak
            Jan 3 at 12:57
















          1














          You can achieve this by looking at the parentBody property of the selection range. The type property on the parentBody will reveal whether the selection is in the 'Header' or elsewhere (see documentation).



          Example



          function determineSelectionInHeader() {
          Word.run(function (context) {
          const HEADER_TYPE = "Header";

          // Retrieve and load 'type' of selection.
          var selection = context.document.getSelection();
          var parentBody = selection.parentBody;
          parentBody.load("type");

          context
          .sync()
          .then(function () {
          if (parentBody.type === HEADER_TYPE) {
          console.log("This is the header");
          }
          });
          });
          }





          share|improve this answer
























          • Perfect, parentBody.type indeed did the trick. Was not aware that headers / footers have their own body.

            – Rvanlaak
            Jan 3 at 12:57














          1












          1








          1







          You can achieve this by looking at the parentBody property of the selection range. The type property on the parentBody will reveal whether the selection is in the 'Header' or elsewhere (see documentation).



          Example



          function determineSelectionInHeader() {
          Word.run(function (context) {
          const HEADER_TYPE = "Header";

          // Retrieve and load 'type' of selection.
          var selection = context.document.getSelection();
          var parentBody = selection.parentBody;
          parentBody.load("type");

          context
          .sync()
          .then(function () {
          if (parentBody.type === HEADER_TYPE) {
          console.log("This is the header");
          }
          });
          });
          }





          share|improve this answer













          You can achieve this by looking at the parentBody property of the selection range. The type property on the parentBody will reveal whether the selection is in the 'Header' or elsewhere (see documentation).



          Example



          function determineSelectionInHeader() {
          Word.run(function (context) {
          const HEADER_TYPE = "Header";

          // Retrieve and load 'type' of selection.
          var selection = context.document.getSelection();
          var parentBody = selection.parentBody;
          parentBody.load("type");

          context
          .sync()
          .then(function () {
          if (parentBody.type === HEADER_TYPE) {
          console.log("This is the header");
          }
          });
          });
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 3 at 9:27









          FluousFluous

          262416




          262416













          • Perfect, parentBody.type indeed did the trick. Was not aware that headers / footers have their own body.

            – Rvanlaak
            Jan 3 at 12:57



















          • Perfect, parentBody.type indeed did the trick. Was not aware that headers / footers have their own body.

            – Rvanlaak
            Jan 3 at 12:57

















          Perfect, parentBody.type indeed did the trick. Was not aware that headers / footers have their own body.

          – Rvanlaak
          Jan 3 at 12:57





          Perfect, parentBody.type indeed did the trick. Was not aware that headers / footers have their own body.

          – Rvanlaak
          Jan 3 at 12:57




















          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%2f54018956%2fcheck-if-text-selection-is-in-header-footer%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

          Npm cannot find a required file even through it is in the searched directory