Rich-text Reply

No redirect when opening multiple Sites at once

GerritS 06-23-16

No redirect when opening multiple Sites at once

[ Edited ]

Hey, 

 

today I realized a bug when you open up multiple URLs of the same test URL at once.

 

So only one of them gets redirected, the other not. 

 

I made a quick screencast to show what I mean:

 

http://screencast.com/t/0dtGFC1v

 

Does anybody have the same issue? 

 

 

Edit: I am running an experiment in optimizely with 4 Variants. Each redirects to another version of the original landing page. So I would assume that the same user always gets redirected to the same page. Usually, that works. But I just realized, when I open up multiple tabs nearly at once, it does not. If I open them with a few seconds in between, the users gets redirected to the same variant. So then it works.

 

Level 2

robertchan 06-23-16
 

Re: No redirect when opening multiple Sites at once

I haven't had that issue, but if you're getting it then just input the following code:

 

function redirect (url) {
    var ua        = navigator.userAgent.toLowerCase(),
        isIE      = ua.indexOf('msie') !== -1,
        version   = parseInt(ua.substr(4, 2), 10);

    // Internet Explorer 8 and lower
    if (isIE && version < 9) {
        var link = document.createElement('a');
        link.href = url;
        document.body.appendChild(link);
        link.click();
    }

    // All other browsers can use the standard window.location.href (they don't lose HTTP_REFERER like IE8 & lower does)
    else { 
        window.location.href = url; 
    }
}

(document.URL == 'http://YOURURL.com') ? redirect('http://google.com') : console.log('Do something else');

The function is from Stack Overflow and the conditional says to redirect to http://google.com based on whether the document URL matches whatever you want. So say your try to make x.com/1 go to x.com/a then you would replace http://YOURURL.com with x.com/1 and http://google.com with x.com/a

Robert Chan

GerritS 06-23-16
 

Re: No redirect when opening multiple Sites at once

Thanks for the answer.

I think I have not been specific enough: I am running an experiment in optimizely with 4 Variants. Each redirects to another version of the original landing page..

If I understand right, with your code I am redirecting to one specific variant, not the one that a user is in the sample of, right?
Level 2
robertchan 06-23-16
 

Re: No redirect when opening multiple Sites at once

No problem, the code does what you are looking for. You would copy and paste the function into your Experiment JavaScript then and just call it in each variant, so...

function redirect (url) {
//everything within this
}

Paste that code into your Experiment JavaScript. Then paste this into each variant:

(document.URL == 'http://YOURURL.com') ? redirect('http://google.com') : console.log('Do something else');

Change http://YOURURL.com to whatever your control page's link is then for each variant, change http://google.com to whatever you want that particular variant to go to, in your case it's going to be the different versions of your homepage.
Robert Chan