Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Anchors and history.back

Featured Replies

Hey Guys,

 

It's been a while. and I'm back with a new problem. Hopefully this time someone can help me..

My problem is that IE , FF and Opera don't scroll back to an anchor by pressing the back button. or using JS history.back().

 

Example:

 

I am at www.website.com/#anchor1

 

and I will click a link that takes me to

 

www.website.com/#anchor2

 

Then I press the back button of my browser. the URL changes to

 

www.website.com/#anchor1

 

but the location of the window doesn't change to #anchor1.

 

 

So, after searching for a while. ( 1 1/2 hours and counting) I can't find anything that helps.

The problem occurs at www.4people.nl if you go to cases and click on any of the top 3 images. and then try to go back.

 

It doesn't have to work with history back. I don't care how it works. as long as I can go back.. So maybe you know a solution or alternative?

 

thanks

You could try a simple jQuery function to check the hash exists, something like this:

 

$(document).ready(function() {
 if(window.location.hash) {
    var h = window.location.hash;
    window.location.hash = h;
 }
});
  • Author

Thanks Lindsey, that was very helpful. In the end this is what I came up with:

 

 

$(document).ready(function() {
 
        $(".checkanchor").click(function(){
 
               setTimeout(function(){
                      if(window.location.hash) {
                            var h = window.location.hash;
                            window.location.hash = h;
                       }
              },500);
 
    });
}); 
  • Author

seems like the code tags still bugs out text below it, and make editting posts a hell.

Since it is a one-page design, loading it on document ready alone isn't enough. So I run the function when someone clicks on a link with the class checkanchor. Then I can into the problem that the browser would run the function before updating the URL. which is why I gave it a delay with setTimeout.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.