“Permission denied to access property 'href' from a non-chrome context” in JavaScript and OpenLayers

断了今生、忘了曾经 提交于 2020-01-24 00:43:29

问题


This is really two questions one leading into the other. Firstly what does 'Permission denied to access property 'href' from a non-chrome context' actually mean?

Secondly I am using overlays in OpenLayers and wish to change the opacity of said layers, this is where this error is being thrown the code of which is here...

<input id='opacity' value="1.0" onChange="changeOpacity()">

Of which changeOpacity() is the following function...

function changeOpacity() {
var newOpacity = parseFloat(OpenLayers.Util.getElement('opacity').value);
newOpacity = Math.min(1.0, Math.max(0.1, newOpacity));
OpenLayers.Util.getElement('opacity').value = newOpacity;
for (var i=0; i<images.length; i++) {
layers[images[i]].setOpacity(newOpacity);
}
}

which throws the error at "var href = originalElement.href;" here...

function mD(e) {
//what is originalElement/srcElement/originalTarget?

var originalElement = e.srcElement || e.originalTarget;

 var href = originalElement.href;

  if (originalElement.nodeName == "A" && href.match("http://www.openstreetmap.org/browse/")) {

    href = href.replace('http://www.openstreetmap.org/browse/','http://www.openstreetmap.org/api/0.6/');

if (gml) { map.removeLayer(gml); } //$("status").innerHTML = 'loading'; }

gml = new OpenLayers.Layer.GML("OSM", href, {format: OpenLayers.Format.OSM});
map.addLayer(gml);
gml.preFeatureInsert = style_osm_feature; 
var sf = new OpenLayers.Control.SelectFeature(gml, {'onSelect': on_feature_hover});
map.addControl(sf);
sf.activate();
return false;

   }
} 

Any help/ideas is great appreciated! I am using firefox 3.5.9 and firebug 1.5.4


回答1:


I've noticed the "Permission denied.." errors often only appear when FireBug is activated. If you disable FireBug these errors never occur.

For layer opacity consider using the GeoExtJS framework on top of OpenLayers. It has a opacity slider widget:

http://www.geoext.org/lib/GeoExt/widgets/LayerOpacitySlider.html



来源:https://stackoverflow.com/questions/2873526/permission-denied-to-access-property-href-from-a-non-chrome-context-in-javas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!