Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

JS history.back not working consistantly

Posted on 2010-01-08
15
Medium Priority
?
526 Views
Last Modified: 2012-05-08
The code in my snippet is a function which is called when the page is done loading.  Basically it is supposed to pop up a save as dialog, and then redirect the user back to their previous location.  This works fine in IE6 and has been working for some time.  The client recently upgraded their machines to IE8.  Now it still works about 80% of the time but 20% of the time the redirect does not occur.

As you can see I was using history.go(-1), I tried changing it to .back() with the same result.  There are are no errors and I am failry certain the code is executing.  THe save as works fine but then 1/5 times it wont do the redirect after the save.  Also the site has been added to trusted sites.   The very strange part is that after it fails, if I click the "back" button manually, nothing happens and the button becomes grayed out.  It is as if the history was wiped out.

One last thing, someone suggested the doctype might be an issue so I tried a couple different ones but the main one I have been using is:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
function doSave()
{

     fullURL = parent.document.URL;
     repID = fullURL.substring(fullURL.indexOf('?')+15, fullURL.indexOf('&'));
     strsave = fullURL.substring(fullURL.indexOf('save')+4, fullURL.length);
          
     if(strsave.length > 1 && strsave.length < 5)
     {
        var bSuccess;
        bSuccess=document.execCommand('SaveAs', '1', repID + ".html");
             
        //history.go(-1);return false;
        history.back();
     }
     
}

Open in new window

0
Comment
Question by:rerard
  • 8
  • 6
15 Comments
 
LVL 83

Expert Comment

by:leakim971
ID: 26217120
Hello rerard,

Do you have a yellow triangle ? If yes what is the error ?

Regards.
0
 
LVL 1

Author Comment

by:rerard
ID: 26217260
No unfortunately not, no indication of any issue.  I would think the code was not running but I put an alert in right before it and the alert will pop up everytime regardless of if the redirect happens.
0
 
LVL 83

Expert Comment

by:leakim971
ID: 26217753
As you said 80% of time so what about EXPIRation of the previous page ?
I assume if you do the back fastly (before cache expire) you can see the previous page.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 2

Expert Comment

by:HaloWebProjects
ID: 26278286
is it possible that the previous page opened the current one using a popup or new window? then that would explain it...

also why dont you use the php referrer instead, its cross compatible to all browsers:

ex:

<a href="<?=$_SERVER['HTTP_REFERER']?>">Go Back</a>

this will render as a link to the previous page, always works
0
 
LVL 1

Author Comment

by:rerard
ID: 26286567
No page expiration is being set and this is a .NET environment so unfortuantely I can't use the php referrer.
0
 
LVL 83

Expert Comment

by:leakim971
ID: 26286757
0
 
LVL 1

Author Comment

by:rerard
ID: 26287427
Even if there is a caching issue, wouldn't that just mean the page was reloaded?  Why does the back button get disabled?
0
 
LVL 83

Accepted Solution

by:
leakim971 earned 1000 total points
ID: 26287527
If the back button is disable there's no available valid previous page.
If the page expir the content is not available.
0
 
LVL 1

Author Comment

by:rerard
ID: 26287701
Ok makes sense, I will take a look this afternoon.
0
 
LVL 1

Author Comment

by:rerard
ID: 26295871
Looks like cache-control defaulted to private, which should be fine, but I set it to public just in case by doing:

<% Response.CacheControl = "public" %>

This had no impact, if anything it made it worse because the first thing I tried failed.  BUT I did leave the page up for a litte longer than usual, so maybe you are on to something.  I am going to look thru the IE settings now and see what I can find there.
0
 
LVL 1

Author Comment

by:rerard
ID: 26295889
Ok weird thing is IE6 has a setting has the "check for newer version" radio set to "everytime I visit the page", and IE8 has it set to "auto"... keep in mind IE6 is the one that is working fine.
0
 
LVL 1

Author Comment

by:rerard
ID: 26295918
Setting IE 8 to "everytime I visit the page" seems like it has resolved the issue but I will test a little more... doesn't this seem counter intuitive though if we think the page is expiring?
0
 
LVL 1

Author Comment

by:rerard
ID: 26307622
Well unfortunately the issue is not resolved though according to the user it is happening less.  I will do some more troubleshooting later today.
0
 
LVL 83

Expert Comment

by:leakim971
ID: 26307672
OK.
0
 
LVL 83

Expert Comment

by:leakim971
ID: 26468710
Thansk for the points!
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question