1

I am trying to call a function from an external javascript file on an "onmousedown" attribute of an SVG element, which works just fine in Edge, Chrome, and Firefox, although Internet Explorer reports that the function is undefined.

I have already tried couple of things, such as wrapping the method inside jquery in $(document).ready, setting an 5 second timeout before calling the function, but nothing seems to work here. Is this a limitation of SVG elements in Internet Explorer, or i'm missing something? My basic code seems like this:

<script src="~/Scripts/myexternalscript.js"></script>

<script>
function MyFunction(evt) {
MyExternalFunction(evt); //Defined in the myexternalscript.js
}
</script>

<div>
    <svg onmousedown="MyExternalFunction(event)" id="SvgjsSvg1001" width="100%" height="100%" xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svgjs="http://svgjs.dev/svgjs"></svg>
</div>

My internal function looks like:

function MyInternalFunction(evt){
...
}

But i already tried other forms, like:

MyInternalFunction = function(evt){
...
}

Thank you for any advice!

wout
  • 2,477
  • 2
  • 21
  • 32
dodo
  • 459
  • 2
  • 8
  • 21
  • Is your external script actually being loaded into the browser? Is the request for it returning 404 or some other error code? – Justin Pearce Sep 25 '18 at 20:31
  • What does your external function do? Is is possible to edit your question to include the source of it? Does IE show a compilation error for this function? Does this function use promises, by any chance? (Promises don't exist in IE but they do in Chrome, Edge and Firefox.) – Luke Woodward Sep 25 '18 at 21:36
  • 1
    Perhaps IE doesn't like the ~ character. – Robert Longson Sep 26 '18 at 01:02
  • Justin: Yes the file is loaded for sure., – dodo Sep 27 '18 at 06:24
  • Robert: The ~ sign is from asp.net razor project, that's not rendered in the html when you open it in the browser. – dodo Sep 27 '18 at 06:25
  • Arrow functions (`=>`) can also be a source of problems with older versions of IE. See https://stackoverflow.com/a/56841207/5802289 – J0ANMM Jul 01 '19 at 19:14

1 Answers1

2

I have finally tracked down the issue in IE debugger, and it seems there was a syntax error in the external file (in another function), and that's why IE said my called function is undefined. So this can be considered as solved, although i don't really understand why a syntax error in another function causing stuff like this in the IE. Just when i thought i have seen it all from the always Great Internet Explorer...

Thank you for the replies anyway!

dodo
  • 459
  • 2
  • 8
  • 21