0

I'm working in correcting js code to be compatible with Micorosoft Edge. I have a problem with <onLoad> and <onSave> events which were working well with Internet Explorer, but not with Ms Edge. I've read that <onSave> is obsolete (https://learn.microsoft.com/en-us/previous-versions/ms531412(v=vs.85)). I wanted to know what re the alternatives for these events ?

.Ascx Page

<div id="divMenu" onchange ="saveState()" onLoad ="loadState()" class="saveHistory" style="display:none;></div>

js file

function loadState(){**Code**}
function saveState(){**Code**}

Thank you in advance :)

I ve found a way to execute onLoad() function by adding this in ascx page but not for onSave(). Is there any alternative for onSave() ?

 <script type="text/javascript">
        window.onload = loadState('divMenu');
  </script>
  • Taking a step back, how exactly is this event being used? What is the actual functionality being implemented? – David May 25 '23 at 16:22
  • Thank you @David for your reply. These events manage a tree menu. Basically, the save event saves the state of selected subcategories of the menu. I want it to be triggered at every click. – radja01 May 25 '23 at 17:01
  • 1
    *"I want it to be triggered at every click."* - Sounds like the `click` event would be the way to go then, no? – David May 25 '23 at 17:04
  • I ve tried window.onclick = saveState('divMenu'); but it didn t get triggered – radja01 May 25 '23 at 17:51
  • That doesn't set `saveState` as a click handler, it sets *whatever `saveState` returns* as the click handler. The code shown doesn't demonstrate what function `saveState` returns, or if it returns one at all. Additionally, inline event handlers like that probably aren't ideal. [`addEventListener`](https://stackoverflow.com/q/6348494/328193) is likely going to be better overall. In particular it looks like you're expecting to handle an event that bubbled up from an element somewhere in the DOM, rather than handling the event directly on the clicked element. – David May 25 '23 at 17:55

0 Answers0