1

How to use onload event in dynamically inserted html file.

For example

<li><a href="sample.html></li>

this line im using in tab panel. When I click on this tab panel header, the sample.html file will inserted in tab panel, in that time I need to trigger the onload event in sampel.html file

<div id="tabs">
  <ul>
    <li>
      <a href="sample.html">load html file</a>
    </li>
  </ul>
</div>
4
  • on click event you need to load html file in tab content? Commented Apr 1, 2016 at 5:51
  • by trigger onload you mean open in new page or on the current page? Commented Apr 1, 2016 at 5:52
  • tab panel is available in index.html file. when i click on tab panel header link, that respective html file will be loaded in tab panel. i have given that html file name in <a href="sample.html">. the sample.html file have the onload event in body tag. so onload event need to trigger in sample .html when that file get inserted Commented Apr 1, 2016 at 6:07
  • is that more simple if you listen on click of this link? don't get the point of "onload event" for tab panel. you can make an ajax call after the link is clicked to get content and insert to tab panel Commented Apr 1, 2016 at 6:36

1 Answer 1

2

I feel something needs to be clarified:

  • onload events are only fired when the "main" HTML page (i.e. window.document) finishes loading for the first time.
  • onload events are not fired when you change a part of your page using Ajax and JavaScript (which is what actually happen when you're using tabs) .

You should really consult the documentation of whichever tabs framework you used, it probably provides other events to detect when a tab changed.

For instance, jQuery has a tabs load event:

$( ".selector" ).tabs({
   load: function( event, ui ) {}
});

// or
$( ".selector" ).on( "tabsload", function( event, ui ) {} );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.