I currently do window.open like so:
window.open(this.fetchClientUrl(), this.clientWindowName, utill.setWindowOptions())
Basically the this.fetchClientUrl()
is https://www.facebook.com/ads/dia?origin=http%3A%2F%2Fmysite.test
, the problem is in mobile the url changes to m.facebook.com
How do I avoid this by changing the user agent in the new opened window ? I.E. How do I do window.open()
and then set the user agent ?
I have tried the below line but it does't seem to work:
this.clientWindow =
window.open(this.fetchClientUrl(), this.clientWindowName, utill.setWindowOptions())
UserAgent(window , "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1");
UserAgent function below:
window.UserAgent = function(window, userAgent) {
// Works on Firefox, Chrome, Opera and IE9+
if (navigator.__defineGetter__) {
navigator.__defineGetter__('userAgent', function () {
return userAgent;
});
} else if (Object.defineProperty) {
Object.defineProperty(navigator, 'userAgent', {
get: function () {
return userAgent;
}
});
}
// Works on Safari
if (window.navigator.userAgent !== userAgent) {
var userAgentProp = {
get: function () {
return userAgent;
}
};
try {
Object.defineProperty(window.navigator, 'userAgent', userAgentProp);
} catch (e) {
window.navigator = Object.create(navigator, {
userAgent: userAgentProp
});
}
}
}
I've looked around StackOverflow and the solution provided here, does't work.