Script can be added to the svg file. This has JS code, but it can be just pulled from somewhere as in the example above.
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" height="210" width="500">
<polygon points="100,10 40,198 190,78 10,78 160,198"
style="fill:lime;stroke:purple;stroke-width:5;fill-rule:nonzero;"/>
<script type="text/javascript"><![CDATA[
window.addEventListener('DOMContentLoaded', () => {
console.log('JS in SVG file executed');
document.documentElement.addEventListener('keydown',function(e){