Avatar of RationalRabbit
RationalRabbit
 asked on

Redirect to Parent Window in IE 11

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?
JavaScriptjQueryAJAXGolang

Avatar of undefined
Last Comment
RationalRabbit

8/22/2022 - Mon
Zvonko

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

Open in new window

ASKER CERTIFIED SOLUTION
Zvonko

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
RationalRabbit

ASKER
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.
RationalRabbit

ASKER
Confirmed after checking. Internet Explorer does not support the includes() method.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Zvonko

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
RationalRabbit

ASKER
Good to know! Thanks.