Linking to a section on another page

I am working on a site and I am trying to build a navigation that links to a section on another page, however it’s not working and I’m not sure why or if there’s some other backend process that is blocking it.

On page 1, I have a section farther down on the page which I called <p id=”trainingsect”></p>

On Page 2, I have a link like this: <a href=”linktopage1.com#trainingsect”>Link to Training Section on Page 1</a>

However, when clicking the link on Page 2, it takes me back to page 1, but does not take me to the paragraph with <p id=”trainingsect”>

The trainingsect id works when I’m on the same page, but it’s not working when I try to link it from another page.

Does anyone have a solution or work around for this?

 

we also tried using this js but no luck

function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\

var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}

var className = getParameterByName('className');
var element = document.getElementsByClassName(className);

element.scrollIntoView();]]>
  • Brenna Lew, can you provide a little more detail. For example are you talking about linking to an anchor in a Collaborate wiki page, or a Collaborate Blog post, or something else entirely?

    In the cases above, Wiki pages support linking to anchor tags, however, Blog pages do not unfortunately - the querystring fragment (#) is thrown away by Collaborate.

  •   They are both home pages linking from one home page, to another home page

  •   , you could try adding this script block into a new content panel at the end of your page content:

     

    <script>
    <![CDATA[
    var hash = window.location.hash.replace(/^(#!){1}/,"");
    if (hash.startsWith("#")) { window.location.hash = hash; }
    ]]>
    </script>

    If you have any visualisations in panels above the content panel with the anchor point, you may find that anchor point position has scrolled out of view again, as the visualisations load and their height's push content further down.

    If that is the case then unfortunately you don't know when all the panels have finished loading.

    There are always tricks and techniques to get round things, but then they become specific to your page rather than a neat "works in all cases" solution.

    NOTE: Posted re-editted on 11/01/2024 to correct the javascript code that wasn't transferred properly from the old Coummity Site post