I use javascript to add a dynamic edit link for maps to the attribution, see demo here: http://pro.mapsmarker.com/?p=11
Works fine in all browsers but IE8 (or lower), where I get an undefined runtime error.
Heres the code (function name are generated dynamically based on map id):
function lmm_addEditLink47cda05c() {
var boundingbox = lmm_map_47cda05c.getBounds().toBBoxString();
if ( document.getElementById('editlink_47cda05c') != undefined ) {
var editlink = document.getElementById('editlink_47cda05c').innerHTML;
document.getElementById('editlink_47cda05c').innerHTML=editlink +' (<a href="http://www.openstreetmap.org/edit?editor=potlatch2&bbox='+boundingbox+'" target="_blank" title="help OpenStreetMap.org to improve map details">edit</a>)';
}
}
lmm_addEditLink47cda05c();
Somehow IE8 seems to have a problem adding a link, cause this code works:
function lmm_addEditLink47cda05c() {
var boundingbox = lmm_map_47cda05c.getBounds().toBBoxString();
if ( document.getElementById('editlink_47cda05c') != undefined ) {
var editlink = document.getElementById('editlink_47cda05c').innerHTML;
document.getElementById('editlink_47cda05c').innerHTML=editlink +' (test with no html link)';
}
}
lmm_addEditLink47cda05c();
Does anyone have an idea how to solve this?
Jarret Minkler answers:
Your missing something
Innerhtml = editLink.innerhtml + ....
Though not sure you want a link inside of another link
I think what you want to do is just add another like to editLinks parent
EditLink.parent().appendChild
Also .... Save the results of your document.getElementById and reuse it. Don't keep searching for the same DOM object
Robert Seyfriedsberger comments:
thx - this (link within a link) was the reason it didnt work in IE8. I also implemented saving of js variables to speed up the script - many thx for pointing that out!
Daniel Yoen answers:
might help : http://stackoverflow.com/a/94744
:-)
Robert Seyfriedsberger comments:
thx, but that doesnt help here...
Daniel Yoen comments:
Sorry,
please try to remove 'boundingbox' variable from the link, if code works, i think it's script execution problem.
more detail here : http://docstore.mik.ua/orelly/webprog/jscript/ch12_03.htm
Robert Seyfriedsberger comments:
no problem.
Removing boundingbox variable doesnt help unfortunately - still the same error.
Dbranes answers:
Hi, are you inserting a link inside a link, i.e. like this <strong><a><a></a></a></strong> ?
Maybe that is problematic in IE8.
What is the html structure for this generated link?
a) You might try to create the DOM elements with Javascript functions like createElement(), appendChild(), setAttribute(), ...
b) or try innerHTML on div instead of a.
... that's my 2 cents ;-)