crowell / modpagespeed_tmp

Automatically exported from code.google.com/p/modpagespeed
Apache License 2.0
0 stars 0 forks source link

Odd error with window.location.href in javascript ? #606

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
This may be difficult to replicate.

I am using a piece of code which uses Ajax to check if a user is logged into a 
site when they click on a certain link - if they are not logged in, then a 
popup appears to allow them to confirm their user details.

If they are logged in, then the javascript uses the line:

window.location.href  = destination;

Where destination is the original link they clicked on.

Say for example, the user is viewing the page:
http://www.example.com/offer/details/1948

The user then clicks on the link to edit the offer - which has the code:
<base href="http://www.example.com/"/>
<a class="buttonX" href="offer/edit/1948">Edit Listing</a>

The ajax code is fired, and checks if the user is logged in (ie. is a cookie 
set).

destination is set to "offer/edit/1948" at this point, so the javascript calls:

window.location.href  = "offer/edit/1948";

This works in browsers, except in Internet Explorer where it tries to pass the 
user to the URL:
http://www.example.com/offer/details/offer/edit/1945

OK - so what does this have to do with mod pagespeed?

If I disable modpagespeed, the code works in IE9.

I have tried disabling rewrite_javascript, and combine_javascript - but the 
code still does not work.

In the end I have had to change the code to ensure that destination always 
begins with the '/' character.

But I am left wondering as to why the code works (a) in non IE browsers, and 
(b) in IE9 when mod_pagespeed is disabled.

Original issue reported on code.google.com by rwap.services on 14 Jan 2013 at 2:51

GoogleCodeExporter commented 9 years ago

Original comment by jmara...@google.com on 14 Jan 2013 at 7:46

GoogleCodeExporter commented 9 years ago
Hmm. Did you notice us moving the <base> tag around? 

How many <base href=> do you have, and where they are located? 
The behavior when there is more than one <base href> and if it's 
after any thing that takes a URL (except html manifest) is 
likely to be different between UA implementations.

Original comment by morlov...@google.com on 14 Jan 2013 at 8:24

GoogleCodeExporter commented 9 years ago
There is only one <base href=> directive and it appears almost at the top of 
the header (and certainly before I load the external javascript code which 
includes the ajax call and window.location.href command.

Original comment by rwap.services on 15 Jan 2013 at 8:49