We help IT Professionals succeed at work.

Redirect to Parent Window in IE 11

RationalRabbit
RationalRabbit asked
on
My login form opens in a modal window (Lightview, which is a jQuery modal). The author has abandoned support, but the modal works great for multiple needs.

I keep a variable, which holds the full path to the current page. On successful login, which is authenticated with an AJAX script, I simply do a relocate to the current page as "parent". That page needs to refresh in order to note the user is logged in and provide a logout button. But it also needs to pull up another model with menu selections for the logged in user. In order to open that menu, I sent a variable to the url, which is picked up in the footer. This all works fine in other browsers, but not in IE11.

So, the process is
1. User presses login button. This brings up the login form in Lightview. (Full path of CurrentPage is held in variable
2. Form is submitted to an AJAX authentication.
3. On success, location is directed back to the current page using
   window.parent.location.href = data.CurrentPage+"?Exp=1";

Open in new window

In browsers other than IE11, this closes the model window, refreshes the current page, the Exp is picked up by a javascript function, and the logged-in menu appears in another modal.

I have tried every way imaginable, including replace, assign, window.top ... nothing seems to work in IE11. It simply does nothing, The page does not relocate and the url does not go to the address bar. Even tried history.go(-1). Any known solutions to this problem?
Comment
Watch Question

ZvonkoSystems architect
Top Expert 2006

Commented:
Try this:
window.parent.location.replace(data.CurrentPage+"?Exp=1");

Open in new window

Systems architect
Top Expert 2006
Commented:
Also be aware that your data.CurrentPage can already contain question mark character.
Then you need additional parameter: +"&Exp=1"
Like this:
window.parent.location.replace(data.CurrentPage+((data.CurrentPage.indexOf('?')>0)?'&':'?')+"Exp=1");

Open in new window

Author

Commented:
Actually, the problem was in some code that you could not see because I, foolishly, did not provide it.
My original code was this:
   if(data.CurrentPage.includes("?"))
   {
      window.parent.location.href = data.CurrentPage+"&Exp=1";
   }
   else
   {
      window.parent.location.href = data.CurrentPage+"?Exp=1";
   }

Open in new window

Apparently, IE11 does not like includes() .  So, even just using window.parent.location works as expected outside the if/else.
That said, in trying to solve the problem, I found a lot of people having problems with IE11 and redirects, so I jumped to that as the problem without thinking further. None of other's solutions worked for me because the redirect was not the problem. Your solution may be helpful to someone else struggling with the IE problem, however.

Finally, thank you for the more eloquent way of dealing with the query string. That eliminates the if/else and, indeed, solves the problem.

Author

Commented:
Confirmed after checking. Internet Explorer does not support the includes() method.
ZvonkoSystems architect
Top Expert 2006

Commented:
Thanks for feedback.

I have just looked up the support for String.includes() and it is realy starting with IE12:
https://www.w3schools.com/jsref/jsref_includes.asp

Regards,
Zvonko

Author

Commented:
Good to know! Thanks.