views:

84

answers:

2

I wonder if its possible to load jQuery within a opera user javascript, so that i can use jQuery functionality in the opera user javascript even on pages that is not currently using jQuery.

A: 

Well it would certainly be possible if you paste the whole lot of jQuery into your UserJS file, or perhaps create a separate UserJS file for all pages with the jQuery library. However, there's a possibility that it would conflict with any pages using jQuery.

Depending on your requirements, maybe you could roll your own mini-framework? For example some simple functions to grab elements by tag/class/id:

function $id(id) {
  return document.getElementById(id);
}

Note: you may get a better response over at Opera's forums.

DisgruntledGoat
Thanks, it worked. An even cleaner way of doing it was to save jquery to the opera userscripts-folder so that it is run on every page. Then i could just use the normal $(document).ready(function() { in my own user javascript file.
RadiantHeart
If you copy jQuery to your user JS folder remember that user scripts run in alphabetical order, so perhaps calling it something like 0-jquery.js helps making it run before all other scripts needing it.(At least we (Opera) implemented alphabetical sorting of user script files back then, don't know if we have explicit tests for that so no idea if it works.. Perhaps I need to fix that.)
hallvors
Good tip, thanks.
RadiantHeart
A: 

Just for completeness:

I use it regularly with my userJS. Just copy your jquery.js into your userJS folder.

OptION 1 to keep it from conflicting with available jquery, use the noConflict option within the jqueryfile and associate jQuery with with your own identifier (jQueryMyIdentifier = jQuery; jQuery = null;) . your JS code can be wrapped with

(function($) {

// normal jquery js based on, jQueryMyIdentifier $('#bla').x();

})(jQueryMyIdentifier);

OPTION 2 check out, how to include a remote js using javascript. implement that include line into your JS. include "http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" or alike.

BananaAcid