5 Replies Latest reply on Apr 3, 2013 2:39 AM by Willam van Weelden

    Need assistance with JavaScipt page reference

    Alberti Level 1

      [RH10, WebHelp Pro]

       

      Hello,

       

      A couple of years ago, someone here kindly provided a script that we use to give our users a feedback e-mail link from any page in the published output. We want to improve the script so that it returns a link not just to the specific page, but to the specific page PLUS the TOC pane.

       

      Currently, the script defines a variable:

       

      var str = location.href

       

      The resulting link is:

       

      http://projectname/robohelp/robo/server/general/projects/projectname/pagename.htm

       

      What modification to the variable or the script is required to produce this link instead:

       

      http://projectname/robohelp/robo/server/general/projects/projectname/default page#pagename.htm

       

      The intention being that the added default page and hash mark would cause the link to open the page in the complete default frameset rather than just the page without the TOC?

       

      Thank you

        • 1. Re: Need assistance with JavaScipt page reference
          Willam van Weelden Adobe Community Professional & MVP

          Hi,

           

          Check this script, this returns exactly that string: Get the CSH URL of a topic: http://www.wvanweelden.eu/blog/2012/08/03/get-csh-url-topic

           

          Also, see Peter's site: http://www.grainge.org/pages/snippets/mailto.htm

           

          Greet,

           

          Willam

          • 2. Re: Need assistance with JavaScipt page reference
            Alberti Level 1

            It appears the script we are using is a variant of the one you linked to on Peter's site. It works well and  Javascript-wise, I don't feel competent to replace it.

             

            Is it not possible simply to insert an additional parameter to the location.href variable so that it captures the default frameset as well as the page name?

            • 3. Re: Need assistance with JavaScipt page reference
              Willam van Weelden Adobe Community Professional & MVP

              You can get the default frameset by

               

              top.location.href

               

              But that doesn't get the URL you want.

               

              The function I linked to does just that. Instead of the document.location statement, reference the function:

               

              var str=CSHURL();

               

              And add the function CSHURL() to the master page or put it in a separate file and link that to your topics.

               

              Greet,

               

              Willam

              • 4. Re: Need assistance with JavaScipt page reference
                Alberti Level 1

                Sorry Willam, but can you walk me through the steps needed to "Add the function to the master page?"

                 

                I copied it to the clipboard and inserted it into the master page using the Insert>HTML>Advanced>Script command but after publishing the output it doesn't seem to be doing anything -- shouldn't I expect to see the URL there? It's just blank.

                 

                Mike

                • 5. Re: Need assistance with JavaScipt page reference
                  Willam van Weelden Adobe Community Professional & MVP

                  Hi,

                   

                  Somewhere, you have a script that produces a URL. I assume that you've added this script to the header or footer of the master page.

                   

                  Now you need to do two things:

                  1. Add the CSHURL() function to the master page.

                  2. Amend the original script to use the new function.

                   

                  To amend your script:

                  1. Open up your script.

                  2. Replace the line var str = location.href with var str=CSHURL();.

                  3. Save,

                   

                  To add the function to the master page:

                  1. Open the master page.

                  2. Select the header or the footer of the master page.

                  3. Click Insert > HTML > Advanced > Script.

                  4. Copy the function CSHURL() to the script.

                  5. Close the dialog.

                  6. Save the master page. You should now see a red square in either the header or footer of the master page.

                  7. Make sure the master page is linked to all topics.

                  8. Generate your output.

                   

                  Enjoy!

                   

                  (

                       Alternatively, you can also paste the function CSHURL() in the same location as the original script. Example:

                       <script type="text/javascript">

                       function myFunction() {

                            //Your code here

                       }

                       function CSHURL() {//Paste the function above or below the other code.

                   

                       }

                       </script>

                  )

                   

                  Greet,

                   

                  Willam