I have a script where I want the browser’s back button to reload the current page, NOT go back to the previous URL.
I figured it’s not possible to attach my own functions to clicking the back button, so I though the next best thing is to manipulate what the latest url is in the history list. Is this possible?
One thing to remember is that onbeforeunload is not a standard event and therefor is only supported by some browsers. Also in those browsers that do support it some people will have become so annoyed at all the “are you sure you want to leave this page” messages that they will have disabled it.
An alternate way that will work except where your visitors have meta redirects disabled would be to set up two web pages where the first consists of nothing except an immediate redirect to the second (plus a link for those with meta redirects disabled). Pressing the back button on the second page will go back to the first page which will immediately redirect back to the second page.
I’d imagine more people would have JavaScript disabled than would have meta redirects disabled and so the meta redirect would be more likely to work that the JavaScript version.
I also just read something like these or similar types of redirects are SEO killers. One source I read said the site wouldn’t be indexed if the search engine came across a redirect. Do you have any experience with this problem?
To see the issue go here click “repair services”. Repair services is print-repair-services.html - the page that has the redirects. It redirects you to print-repair-servicescopy.html. Now click the ‘home/office inkjet’ link and try clicking back. It will take you to print-home.html, NOT print-repair-servicescopy.html…
I noticed that refreshing the page will put it in history and create the situation I need for the back button to refresh the current page and not actually go back.
Now this short simple script I wrote is looping, it shouldn’t loop. It’s in an external file.
What does it take to get a URL to file in the browser’s history?? Now on print-repair-services.html I have a redirect on window.onload that redirects to print-repair-servicescopy.html and print-repair-services.html still isn’t listed in the history…
That depends on the type of redirect that’s performed.
If it’s a meta-refresh redirect then the browser often believes that it shouldn’t store the original page in its history. There’s no point, as it is of no use and you should be going to the redirected page instead.
If you use some javascript though to change the location.href to another page, then the original will be kept in the history.
I’m not sure why you’re doing this at all, and to be honest I hate going to websites when I have to repeatedly click the back button to get back to previous pages - I’m sure other web users find it equally as annoying. - Have you considered usability?
Repair services (or, print-repair-services.html) is the link/file that has this redirect:
window.onload = init;
function init(){
location.href = "http://www.chris-rawlins.com/codenesi/print-repair-servicescopy.html";
}
in an external file.
So the link “repair services” links to print-repair-services.html which redirects you to print-repair-servicescopy.html. And when I check the history when I’m on print-repair-servicescopy.html it is this page not the page that I was redirected from.
I think I should explain what I was trying to do with all of this redirect code.
If you go here and click any of the thumbnails in the main content area (home/office inkjet, multifunction, etc), you’ll notice that only the content in the main content area changes - the sidebar info, footer, etc stay the same.
I thought I would be able to use js to only, for example if scanners was clicked, change the scanner corresponding main content information, instead of making separate html files that include all the same code for the header, sidebar, etc.
If javascript was disabled there would be default html files available, so maybe I should just use separate html files. If the redirect idea didn’t work I figured to use js I’d have to put a button in the main content area as a trigger to reload the original print-repair-services.html page info but I’d rather not do that.
Part of me thinks since I’m trying to use js to reload content on a different page its not the right tool for the job.