Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirecting problem in Internet Explorer 11 (IE11) #17434

Closed
art40100 opened this issue Jul 15, 2019 · 8 comments
Closed

Redirecting problem in Internet Explorer 11 (IE11) #17434

art40100 opened this issue Jul 15, 2019 · 8 comments
Labels
Milestone

Comments

@art40100
Copy link
Contributor

What steps will reproduce the problem?

Performing an ajax request and doing a redirect from it.
(Issue when using Internet Explorer 11 (IE11))
Related (same issue) #9670

What is the expected result?

A successful redirect to given URL in function Response::redirect()

What do you get instead?

No redirect!
jokeie11

Additional info

Using 308 statusCode (default is 302) solves the problem in general but it is probably not the right way to do this.
return Yii::$app->getResponse()->redirect(['aaa/view', 'id' => $this->lid], 308);

Q A
Yii version 2.0.22
PHP version 5.6.40
Operating system W10x64
@samdark samdark added this to the 2.0.23 milestone Jul 15, 2019
@samdark samdark added the type:bug Bug label Jul 15, 2019
@art40100
Copy link
Contributor Author

art40100 commented Jul 15, 2019

Quick and dirty solution - extending the Response class and overriding redirect()

class CResponse extends \yii\web\Response
{
    /**
     * @inheritdoc
     */
    public function redirect($url, $statusCode = 302, $checkAjax = true)
    {
        $browser = Yii::$app->browser;
        $browserName = $browser->getName();
        if (Yii::$app->getRequest()->isAjax 
            && ($browserName === $browser::IE)
        ) {
            return parent::redirect($url, 308, $checkAjax);
        } else {
            return parent::redirect($url, $statusCode, $checkAjax);
        }
    }
}

@samdark
Copy link
Member

samdark commented Jul 16, 2019

@art40100 what's Yii::$app->browser?

@alex-code
Copy link
Contributor

This should work in JS to use the frameworks redirect handling.

var ua = window.navigator.userAgent;
if (ua.indexOf('MSIE ') > 0 || ua.indexOf('Trident/') > 0 || ua.indexOf('Edge/') > 0) {
  $(document).ajaxSend(function(event, jqXHR, ajaxOptions) {
      jqXHR.setRequestHeader('X-Ie-Redirect-Compatibility', 'true');
  });
}

@samdark samdark removed this from the 2.0.23 milestone Jul 16, 2019
@art40100
Copy link
Contributor Author

@art40100 what's Yii::$app->browser?

in config/main.php

'components' => [
    'browser' => [
        'class' => 'Sinergi\BrowserDetector\Browser',
    ]
];

A library installed in my project via composer (https://packagist.org/packages/sinergi/browser-detector)

@samdark
Copy link
Member

samdark commented Jul 16, 2019

OK. That may work for you but isn't a good solution for the framework.

kamarton pushed a commit to kamarton/yiisoft-yii2 that referenced this issue Aug 23, 2019
@kamarton
Copy link
Contributor

@art40100 please check this fix: #17525

@samdark samdark added this to the 2.0.26 milestone Aug 23, 2019
kamarton added a commit to kamarton/yiisoft-yii2 that referenced this issue Sep 3, 2019
…e codes (`XMLHttpRequest: Network Error 0x800c0008`) fix yiisoft#17434
@samdark samdark closed this as completed in 10a069a Sep 3, 2019
kamarton added a commit to kamarton/yiisoft-yii2 that referenced this issue Sep 10, 2019
samdark pushed a commit that referenced this issue Sep 10, 2019
…r Internet Explorer 11 AJAX redirect bug in case of 301 and 302 response codes (`XMLHttpRequest: Network Error 0x800c0008`)
@fl0v
Copy link

fl0v commented Nov 15, 2019

if (in_array($statusCode, [301, 302]) && preg_match('/Trident.*\brv:11\./' /* IE11 */, $request->userAgent)) {

The fix applyed breaks compatibility by removing check for X-Ie-Redirect-Compatibility header used in previos releases:

if (Yii::$app->getRequest()->getHeaders()->get('X-Ie-Redirect-Compatibility') !== null && $statusCode === 302) {

There are special windows versions (for tablets or IoT devices) that send custom user agent that does not include standard IE11 signature checked by preg_match('/Trident.*\brv:11\./' /* IE11 */, $request->userAgent). Ex:

Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.2; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; Tablet PC 2.0)

It could be usefull to refactor the code to be able to activate this IE11 hack using request headers as before release 2.0.26 and maybe add a \yii\web\Response flag

@kamarton
Copy link
Contributor

This is true. I do not know that I did not notice the other versions of IE checking.

https://github.com/SilverFire/jquery-pjax/blob/017ef68cc7fe998377e37b380ccf645e3714ecca/jquery.pjax.js#L235-L237

      if (ua.indexOf('MSIE ') > 0 || ua.indexOf('Trident/') > 0 || ua.indexOf('Edge/') > 0) {
        xhr.setRequestHeader('X-Ie-Redirect-Compatibility', 'true')
      }

kamarton added a commit to kamarton/yiisoft-yii2 that referenced this issue Nov 16, 2019
kamarton added a commit to kamarton/yiisoft-yii2 that referenced this issue Nov 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants