skip to Main Content

The answer to this question may be simple, but due to my inability to phrase it very well, I’ve been having a hard time finding search results on what I’m looking for.

Here is my issue: my page operates by displaying plain HTML files (that is HTML files with little to no CSS styling) onto a "mother" page that has all the CSS styling to make everything look nice. For example: let’s say on https://mywebsite.com I have the following code:

<a href="#pictures" onclick="changecontent(1); return false;">click for pictures</a>
and if (page == 1) $("#content").load("/pictures.html");

This works just fine. However, if I want to link people specifically to my pictures section on my page…how can I do that without linking the actual pictures.html? I’ve changed return false to return true and while it changes my webpage’s URL after clicking the link to this:

https://mywebsite.com/#pictures

actually putting https://mywebsite.com/#pictures into the URL bar just takes me to the default https://mywebsite.com. So, how do I go about linking a page with changed content on it? Many thanks!

2

Answers


  1. Here are some examples on various ways to load the page

    <a href="/pictures.html" class="contentLink">click for pictures</a> 
    
    $(() => {
      // clicking will load it into content - do NOT do this to have the link go to the page
      $('.contentLink').on('click',(e) => { 
        e.preventDefault(); // stop the link
        $("#content").load(e.target.closest('a').attr('href'));
      });
      // if page == 1 on page load, load the first of those links into content
      if (page == 1) {
        $("#content").load($('.contentLink').eq(0).attr('href'));
      })
    });
    
    Login or Signup to reply.
  2. add this to your page

    <a href="javascript:void();" onclick="changecontent(1);">click for pictures</a>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search