0

i want my html page triggers & shows the native, default context menu on page load as if a human user has clicked on a div which has an ID in internet explorer 11.

more specifically, my div has a SVG. If a right-click it on IE11, it shows the context menu "share image, save as image etc.."

My best try is below and it's not working.

IE11 console says "SCRIPT5007: SCRIPT5007: Unable to set property 'onmousedown' of undefined or null reference".

Firefox console gives no error.

  • Why is it not working?
  • How to achieve my purpose on Internet Explorer?

jsbin representation of my exact source code:

https://jsbin.com/fepeqetegu/edit?html,output

thanks.

<body>
    <div id="target">
        <!-- a SVG content -->
    </div>

    <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>

    <script>
        $("document").ready(function() {
            setTimeout(function() {
                $("#target").triggerHandler('contextmenu');
            }, 100);
        });
    </script>
</body>
sokorro
  • 13
  • 4
  • https://stackoverflow.com/questions/7914684/trigger-right-click-using-pure-javascript does this help your question? – Luckylazuli Nov 10 '20 at 08:12
  • it doesn't work either. But "no error" on IE11 console in this time. – sokorro Nov 10 '20 at 08:20
  • Mhh strange. OS? 10? – Luckylazuli Nov 10 '20 at 08:46
  • yes windows 10. i created a jsbin representation of my exact source code. https://jsbin.com/fepeqetegu/edit?html,output – sokorro Nov 10 '20 at 08:53
  • I tried to make a test with several other code examples but nothing worked so far. Can you please inform us of the purpose of triggering the context menu? It can help us to understand your overall requirement and we can try to find a possible workaround for it. – Deepak-MSFT Nov 11 '20 at 06:38
  • I want to automatize the ability of IE11's "save as PNG". I will have a bunch of SVGs in a folder. My environment is very restricted. My main app lang is PHP however I can't -for example- install any PHP lib to convert SVGs to PNGs. I thought it was easy for jquery: trigger context menu -> walk through buttons -> fire "save as .." button in proper order . I don't know js/jquery by the way. I research and then try to apply. – sokorro Nov 11 '20 at 07:30
  • As I informed you in the previous thread, whenever you try to download the file then IE will show you a save file dialog and it is not possible to control it using the JQuery. So you need another approach to download the SVG images as PNG from the site. Thanks for your understanding. – Deepak-MSFT Nov 12 '20 at 07:17

0 Answers0