Search code examples
htmlurlhyperlinktagsanchor

Linking to specific part of a webpage, that doesn't have an anchor tag


How do I create a link to a part of long webpage on another website that I don't control, that doesn't have an anchor tag?

I am trying to create a Course Outline Finder chrome extension for my university that you can use to:

  • Type course code in input box. (Use JS to filter out all other course codes)
  • Click the course code that remains after entering course code.
  • Course code link then leads you to a specific part of the university webpage that shows a list of course outlines for that specific course.

Ideally the webpage would have given an anchor tag like the following:

<h2 id="anchor">COMP150</h2>

Which I would then be able to link by doing the following:

<a href="https://www.ufv.ca/calendar/CourseOutlines/PDFs/COMP/#anchor>

But the website unfortunately doesn't have any id's for the h2 tags. It instead has this:

    <h2>COMP 150</h2>
      <ul>
        <li><a href="COMP150-20000927.pdf">COMP150-20000927.pdf</a>Effective Fall 2012</li>
        <li><a href="COMP150-20011207.pdf">COMP150-20011207.pdf</a>Effective Fall 2019</li>
      </ul>

Is there anything I can do?


Solution

  • I found a solution using text (instead of anchors) by JOUTI here:

    https://stackoverflow.com/questions/2835140/how-do-i-link-to-part-of-a-page-hash#:~:text=JOUTI

    Test:

    https://stackoverflow.com/questions/2835140/how-do-i-link-to-part-of-a-page-hash#:~:text=Click%20on%20this%20link