jQuery in widget

前端 未结 2 1471
长情又很酷
长情又很酷 2021-01-05 19:36

I want to use jQuery in an add on JS library that can be added to random websites. These websites may or may not use jQuery already.

I have 3 questions around this a

相关标签:
2条回答
  • 2021-01-05 20:14

    You can try the solution in the following link if it works for you. Basically, there is a plugin that creates widgets on the fly and then asynchronously requests another page url, and sets the returned content as inner html of the widget.

    http://sites.google.com/site/spyderhoodcommunity/tech-stuff/jquerydashboardwidgetplugin

    0 讨论(0)
  • 2021-01-05 20:22

    This is pretty loose and incomplete -- and really is meant to be a starting point:

    if (typeof $ != 'undefined') {
        var msg = 'This page already using jQuery v' + $.fn.jquery;
    } else {
        var s = document.createElement('script');
        s.setAttribute('src', 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js');
        document.getElementsByTagName('head')[0].appendChild(s);
        var msg = 'This page is now jQuerified';
    }
    

    then wait via a brief setTimeout() before running a ready() function

    0 讨论(0)
提交回复
热议问题