Uncaught ReferenceError: editDiagram не определен в HTMLImageElement.onclick - PullRequest
0 голосов
/ 25 сентября 2018

Я создал изображение в моем jsp, событие onclick которого вызывает функцию editDiagram, определенную в файле .js.

<img id="image" style="max-width:100%;cursor:pointer;" 
  onclick="editDiagram(this); " src="data:image/png;base64,ibeGiQpg9Yt ...>

Соответствующий файл .js для страницы содержит функцию, как показано ниже-

   function editDiagram(image)
        {
            var initial = image.getAttribute('src');
             image.setAttribute('src', 'http://www.draw.io/images/ajax-loader.gif');
            var iframe = document.createElement('iframe');
            iframe.setAttribute('frameborder', '0');

            var close = function()
            {
                image.setAttribute('src', initial);
                document.body.removeChild(iframe);
                window.removeEventListener('message', receive);
            };
            var receive = function(evt)
            {
                if (evt.data.length > 0)
                {
                    var msg = JSON.parse(evt.data);

                    if (msg.event == 'init')
                    {
                        iframe.contentWindow.postMessage(JSON.stringify({action: 'load',
                            xmlpng: initial}), '*');
                    }
                    else if (msg.event == 'export')
                    {
                        close();
                        image.setAttribute('src', msg.data);
                        save(location.href);
                    }
                    else if (msg.event == 'save')
                    {
                        iframe.contentWindow.postMessage(JSON.stringify({action: 'export',
                            format: 'xmlpng', spin: 'Updating page'}), '*');
                    }
                    else if (msg.event == 'exit')
                    {
                        close();
                    }
                }
            };
            window.addEventListener('message', receive);
            iframe.setAttribute('src', 'https://www.draw.io/?embed=1&ui=atlas&spin=1&modified=unsavedChanges&proto=json');
            document.body.appendChild(iframe);
        };

        function save(url)
        {
            if (url != null)
            {
                var req = new XMLHttpRequest();
                req.withCredentials = true;

                req.onreadystatechange = function()
                {
                    if (req.readyState == 4)
                    {
                        if (req.status < 200 || req.status > 299)
                        {
                            alert('Error ' + req.status);
                        }
                    }
                };

                req.open('PUT', url, true);
                req.send(document.documentElement.outerHTML);
            }
        }

Всякий раз, когда я нажимаю на изображение, я получаю сообщение:

  1. Uncaught ReferenceError: editDiagram не определен в HTMLImageElement.onclick
  2. Uncaught ReferenceError:editDiagram не определен в HTMLImageElement.eval (eval at (jquery.min.js: 2),: 5: 5) в HTMLImageElement.dispatch (jquery.min.js: 3) в HTMLImageElement.r.handle (jquery.min.js: 3)

В чем проблема с кодом?

...