Stelzy
Stelzy

Reputation: 1

Internet Explorer / Edge not sending fragment with URL

I am currently developing a website my company needs to deploy on the most significant browsers (Chrome, Firefox, Safari, IE, Edge).

The website consists of a single index.html page, with a whose content is being replaced depending on the hash code. That means when I ask for index.html#102, the content of the div gets replaced with, say, contents[102].

My problem is : when asking for 'file:///.../index.html#102' (the website will be stored locally), Internet Explorer (10, 11) and Edge get rid of the #102 and actually ask for 'file:///.../index.html'. So I basically end up on the homepage every single time... Chrome, Firefox and Safari all ask for 'index.html#102' (awesome !), IE and Edge are the only ones deleting the '#102'.

Do you happen to know why ? I spent my whole day looking for an answer, and trying the solutions provided for similar issues (Keeping URL Fragments when redirecting in Internet Explorer, Fragment ID in URL Not Working, https://www.daniweb.com/programming/web-development/threads/428644/url-hash-gets-removed-in-ie-after-redirect, https://blogs.msdn.microsoft.com/ieinternals/2011/05/16/url-fragments-and-redirects/) but none of them worked.

I understand hash codes are local and will never be sent to servers : is it possible that IE / Edge think my request is sent to a server ?

I am a beginner developer, trying to help the company on those issues, this is not my full-time job, so I reckon I might have missed a few critical pieces of info for you to help me = feel free to ask for details.

Upvotes: 0

Views: 666

Answers (2)

Prathap Reddy
Prathap Reddy

Reputation: 1739

I am not sure if this Q & A helps you after 2 years.

Posting this to save time for someone who's facing the similar issue. Hope they won't struggle like me with the same issue again.

Posting working solution for me

We use SiteMinder authentication in our application.

I figured out that after successful authentication, SiteMinder is doing 302 redirection to user requested application page by using login form hidden variable value (where it stores user requested URL /myapp/ - without hash fragment since it won't be sent to the server) with name similar to redirect. Sample form below

Sample login form

Since redirect hidden variable value contains only /myapp/ without hash fragment and it's a 302 redirect, the hash fragment is automatically removed by IE even before coming to our application and whatever the solutions we are trying in our application code are not working out.

IE is redirecting to /myapp/ only and it is landing on default home page of our app https://ourapp.com/myapp/#/home.

Have wasted almost a day to figure out this behavior.

The solution is:

Have changed the login form hidden variable (redirect) value to hold the hash fragment by appending window.location.hash along with existing value. Similar to below code

$(function () {
  var $redirect = $('input[name="redirect"]');
  $redirect.val($redirect.val() + window.location.hash);
});

After this change, the redirect hidden variable is storing user requested URL value as /myapp/#/pending/requests and SiteMinder is redirecting it to /myapp/#/pending/requests in IE.

The above solution is working fine in all the three browsers Chrome, Firefox and IE.

Thanks to @AlexFord for the detailed explanation and providing solution to this issue.

Upvotes: 0

Sandeep Manware
Sandeep Manware

Reputation: 11

In the form tag add attribute onsubmit="window.location.reload()" for only IE

or you can add it with jQuery $(yourfoemid).attr('onsubmit',window.location.reload());

or you can write it on document.ready.

Upvotes: 1

Related Questions