Setting a custom userAgent in HTML or JavaScript

前端 未结 4 1448
野趣味
野趣味 2020-12-17 10:03

Is there any way to do this? I\'m trying to send a GET request to a website, but I want to customize my UserAgent. Is there any way to do this in pure HTML and JavaScript? I

4条回答
  •  旧巷少年郎
    2020-12-17 11:04

    This is working for me.

    Object.defineProperty(navigator, 'userAgent', {
        get: function () { return 'Mozilla/5.0 (Windows NT 6.2; WOW64; 
        rv:28.0) Gecko/20100101 Firefox/28.0)'; }
    });
    

    It is an updated version of code4coffee's answer as Object.prototype.__defineGetter__() is deprecated: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineGetter

提交回复
热议问题