2

If the user is at url foo.com/#/veryLongToken and the response.redirectUrl is foo.com/#/veryLongToken/resultToken , in the first example, when the page is reloaded we end up at foo.com/#/veryLongToken. In the second example, we end up at foo.com/#/veryLongToken/resultToken which is what we expect.

More info;

  • The URL is very long
  • AngularJS window-wrapper $window is used
  • Tested in Chrome and Safari, both displaying same behaviour

Doesn't work:

function successHandler(response) {
   $window.location.href = response.redirectUrl;
   /* redirectUrl might contain only changes to the hash-fragment
      which is why we force a reload here */
   $window.location.reload();
}

Works;

function successHandler(response) {
   $window.location.hash = response.redirectUrl.substr(response.redirectUrl.indexOf('#'));
   $window.location.reload();
}

I'd really like to know why the first example doesn't work. Any ideas?

UPDATE: $window.location.href is https://foo.fo.se/#/payment/Ak1ZWDg1MDhJAwJWVElOUE5WVEZQSQMCAwIDAgMCAwIDAgMCTVlYODUwOEkDAgMCAwIDHQDSqdsSYXcT5rdNEkrClAYdawRZXF3vwZUSSb9_XHeQTFJcyJxnQXnz1V4gQCTgm7q9OYmLKMFVEaCaZM8RX6iIExvQZT7uPjtfYowjvvU-JpO8yMhTquehcBOo_JEXqCskKVStCp25qWq4GdPXgP3f1KthAO17OOAdLHKMNm8bmNW8Nj-P_xltDTV22ZHABQS_4d0DcWSDj7ZfUK3q28zZ9pLdedu3sjblzmXqDiSBNEuDQfQOjMt_s0xlayYX0qUwJwwviaZ8aB-qLRnV7KD_LvaESGrtwq7_iiNIoB1jeFAp0dSG_N1c-5V-VZ3100DbJBoecTIF4NaCS62IxfM

response.redirectUrl is

https://foo.fo.se/#/payment/AkpITDg0ODFIAwIwTDNWVkwzMzcwSgMCAwIDAgMCAwIDAgMCSkhMODQ4MUgDAgMCAwIDHTQ1Z7gveX-CH7OzdVcAtOtar9mOZQF8f4t7MFIM5b1_WU7BAEtYPfSD77sFsGmHnm4GoFMmsIHUCzscUiaP2iofV7rflegQADTieSpwbausFLn6FNmaVeZdlFEtoWr6cU1VlN09zqk4T-1cqheoDsb_jMWr3kTdZGkJh_168P99zjV324jpDIkKAZ12WFXuaphnGdNoJgP9Ka9S2aIi8LniCiJNtOq-iXL4w8JNYVyLrbOqB2QNpc__RtT5kcW9NEaPWehQx2S5CIB157RcI_WkeGJRb1DKSSuy8CFIYJVrEOlCb-GtZ9gmPhrLh6qPiumokJWSI2cUuFBDpaGAeiA/AkpITDg0ODFIAwJJTlRFUk5BTF9FUlJPUgMCAwIDAgJJTlRFUk5BTF9QUk9DRVNTX0RFQklUX05PTl9SRUNPVkVSQUJMRQMD

Soroush Hakami
  • 5,226
  • 15
  • 66
  • 99
  • try $location.path('url') but dont forget to add it to your Conroller .controller('blaCtrl', function ($location){} – stackg91 Jun 30 '15 at 12:09
  • my understanding of $location is that it's just a higher level service than $window, see http://stackoverflow.com/questions/16002984/angularjs-how-can-i-do-a-redirect-with-a-full-page-load , or do you have more information? – Soroush Hakami Jun 30 '15 at 12:33

2 Answers2

0

As a # in a URL mark an anchor, the changing of it don't trigger a page load as your bas url (foo.com/) stay the same. The window.location.href isn't ment to hadle anchor change.

If you whant to change the "anchor" part, you must use the window.location.hash for it to be detected (as in your second exemple)

Remy Grandin
  • 1,638
  • 1
  • 14
  • 34
  • Understood, but if I change it anyways, and then do window.location.reload() afterwards, it is my understanding that it should work anyways? See http://stackoverflow.com/questions/10612438/javascript-reload-the-page-with-hash-value – Soroush Hakami Jun 30 '15 at 12:28
  • 1
    The js specification don't force it (the # change detection in href) so it's up to every browser implementation. As the hash filed is avaialble for this, it's understandable they don't allow it in the href. After, maybe angular do some stuff there, i don't know enoght in angular to answer more. – Remy Grandin Jun 30 '15 at 12:34
-1

Every browser has a URL length limits! the shortest one is Internet Explorer which is 2083 characters! Check it out here

And all webkit browsers Chrome, Safari, Mozilla has a limit of 100KB! You can get more details here

Pratik Shah
  • 788
  • 5
  • 8
  • Thanks for the info. I think in this case, that the URL is definetly within the allowed length. – Soroush Hakami Jun 30 '15 at 12:29
  • Can you share the actual URL so that we can get better insight of the problem! – Pratik Shah Jun 30 '15 at 12:42
  • Sure, here's the actual URL: https://foo.fo.se/#/payment/Ak1ZWDg1MDhJAwJWVElOUE5WVEZQSQMCAwIDAgMCAwIDAgMCTVlYODUwOEkDAgMCAwIDHQDSqdsSYXcT5rdNEkrClAYdawRZXF3vwZUSSb9_XHeQTFJcyJxnQXnz1V4gQCTgm7q9OYmLKMFVEaCaZM8RX6iIExvQZT7uPjtfYowjvvU-JpO8yMhTquehcBOo_JEXqCskKVStCp25qWq4GdPXgP3f1KthAO17OOAdLHKMNm8bmNW8Nj-P_xltDTV22ZHABQS_4d0DcWSDj7ZfUK3q28zZ9pLdedu3sjblzmXqDiSBNEuDQfQOjMt_s0xlayYX0qUwJwwviaZ8aB-qLRnV7KD_LvaESGrtwq7_iiNIoB1jeFAp0dSG_N1c-5V-VZ3100DbJBoecTIF4NaCS62IxfM (the **redirectUrl** is this URL + a slash and another token) – Soroush Hakami Jun 30 '15 at 12:46