简体   繁体   中英

Ajax content loading issues

Following is my code which I am using to load contents dynamically. The issues which I am facing are the following:

Following code has now disabled CTRL+CLICK shortcode to open a url in a new tab. The new CSS and JS are not applying if they are not already exist in the previous page. Kindly let me know how can I resolve above mentioned issues?

 $(document.body).on("click", "nav a", function () {
      topen = $(this).attr("href");
      window.location.hash = $(this).attr("href");
      $("#main_wrapper").load( topen +" #main_wrapper > *");
      return false;
 });

What you want to do is modify the handler to use prevent default instead of returning false. Then you can check how the user activated the button and can act accordingly.

$(document).ready(function() {
    $('a').on('click', function(e) {
        if(e.ctrlKey || e.button === 1) {
            return;
        }
        e.preventDefault();
        // Do the stuff when the anchor is just clicked.
    });
});

You can examine the Fiddle

In terms of the JS and CSS not applying we would need a working example of this to be of more assistance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM