Home > Software engineering >  How to redirect to same place on page when redirecting to previous page
How to redirect to same place on page when redirecting to previous page

Time:01-08

I was wondering if there is a way in django for when you click back to go to the previous page via a link or in my case an anchored link with in an img, for it to also end up in the same place as you click originally, in my case the image that is clicked in the first place.

Page I click image to redirect:

 </head>
  <body>
    <header>{% include 'navbardesktop.html' %}</header>
    <div >
      <div >
        <a href="{% url 'gallery' %}"
          ><img  src="{{photo.image.url}}"
        /></a>
        <h2 >{{photo.image_title}}</h2>
        <p >
          Interested in purchasing this as a print? Contact me for more
          information regarding price and sizes.
        </p>
        <a href="{% url 'contact' %}"  type="button"
          >Contact</a
        >
        <a href="{% url 'gallery' %}"  type="button"
          >Gallery</a
        >
      </div>
    </div>
  </body>
</html>

Page I want to redirect to:

  <body>
    <header>{% include 'navbardesktop.html' %}</header>
    <div >
      <div  id="gallerygrid1">
        <div >
          {% for photo in images %}
          <div  id="gallerygrid2">
            <a href="{% url 'viewimage' photo.slug %}"
              ><img
                
                src="{{photo.image.url}}"
                style=""
            /></a>
          </div>
          {% empty %}
          <h3>No Projects...</h3>
          {% endfor %}
        </div>
      </div>
    </div>
  </body>
</html>

CodePudding user response:

You could do a js event on the element that takes you to the other page and then add inClick event which will store the amount of the current scrolling in local storage and when you go back it will check the amount of scrolling that stored in the browser's local storage and do the scroll.

  • Related