I have an HTML page with external JavaScript module
<script type="text/javascript" src="js/js.js"></script>
and an external SVG map "img/map.svg".
I need to make clickable objects on the map which will in turn call some global JavaScript function myJSFunction defined in "js/js.js". This function will modify the title and contents of the HTML page, hide the SVG map and display a table with some data instead. How can I do this? A naive attempt to set an onclick event in the svg code like the following:
<g
id="g170"
onclick="myJSFunction()">
results in error:
Uncaught ReferenceError: myJSFunction is not defined at SVGGElement.onclick
function myJSFunction() { alert("clicked!"); }. And the script loading code is placed after<object data="img/map.svg" ....myJSFunction()from the console in Chrome, it works!window.parent.myJSFunction();works!