使用javascript禁用地理位置浏览器

使用javascript禁用地理位置浏览器,javascript,geolocation,Javascript,Geolocation,我正在使用QUnit编写一个集成测试,在我的webapp中,如果地理位置不可用,(我使用if(navigator.geolocation)来检测是否存在,但我想禁用它,以便在地理位置不可用时实施测试 我尝试了navigator.geolocation=undefined,但不幸的是,它不起作用。您不能真正“禁用”,因为它是只读属性 相反,您可以创建一个检查特定功能的包装器,然后为您的测试模拟它 var supports = { geolocation: !!navigator.geoloca

我正在使用QUnit编写一个集成测试,在我的webapp中,如果地理位置不可用,(我使用
if(navigator.geolocation)
来检测是否存在,但我想禁用它,以便在地理位置不可用时实施测试

我尝试了
navigator.geolocation=undefined
,但不幸的是,它不起作用。

您不能真正“禁用”,因为它是只读属性

相反,您可以创建一个检查特定功能的包装器,然后为您的测试模拟它

var supports = {
  geolocation: !!navigator.geolocation // will be `true` if geolocation is defined
};

// In your tests...
supports.geolocation = false;
executeTest();
您不能真正“禁用”,因为它是只读属性

相反,您可以创建一个检查特定功能的包装器,然后为您的测试模拟它

var supports = {
  geolocation: !!navigator.geolocation // will be `true` if geolocation is defined
};

// In your tests...
supports.geolocation = false;
executeTest();