1

I found the code to set the userAgent at runtime in my application,in IE11 Chrome and FF by definegetter. Same doesn't work in IE10,9,8. Is this even possible? Referred Mocking a useragent in javascript?

EDIT

My Tryout code in IE 8 which didnt work.Error comes

Object doesnt support this action Object.defineProperty as said by TechLiam works in FF, Chrome and IE9+

if (navigator.appVersion.indexOf('MSIE 8.') != -1){
            try 
            { 
                delete navigator; 
            } 
            catch(e) 
            { 
                //window["navigator"] = undefined; 
                if(Object.defineProperty){
                    Object.defineProperty(navigator,'userAgent',{
                      get: function() { return bValue; },
                      set: function(newValue) { bValue = newValue; },

                      configurable: true
                    });
                }
            }
        }
Community
  • 1
  • 1

1 Answers1

1

I think thia https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty#Internet_Explorer_8_specific_notes may help have a look at the Browser compatibility table and the Specifications table as they can tell you alot about what this is meant to do

TechLiam
  • 137
  • 1
  • 3
  • 10
  • #TechLiam I am not able to set navigator userAgent in IE8. Was able to do it through defineProperty in all other browsers. Read the link u had given above. I tried to modify existing property 'navigator' by first deleting it and creating a new one.See my edit for the tryout I made – Pratik Pattanayak Feb 25 '15 at 06:10