How can I use jQuery and Javascript from firefox add-on? -
I can not create a new element in the page when the page is onload, then I check the page and domain, it It's work, but I do not know how I can create a new element in the right window page.
window.addEventListener ("load", function () {myExtension.init ();}, false); Var myExtension = {init: function () {var app content = document. GetElementById ("apparmat"); // Browser if (appontent) appentant.endantostenor ("Dome content loaded", my extension. Open page, true); }, OnPageLoad: function (aEvent) {var unsafeWin = aEvent.target.defaultView; If (unsafe. WrappedJSObject) unsafe Win = unsafe WrappedJSObject; Var Location = New XPC Native Vapor (unsafe, "location") place; Var hostis = locationis.host; // warning (hostis); If (hostis == 'domain.com') {var pathnameis = locationis.pathname; If (pathnameis == '/ index.php') {$ ("#left. Box: eq (0)") ('& Lt; div id = "organic-tabs" class = "box" & gt; & lt; / div & gt;'); // This code is not working in any way, but if I copy FireBug to work it}}}} My question is that when I'm in the right window content If I want to manipulate HTML, how can I use javascript and jquery with Firefox addon? What is required from here
$ ("# left. Box: eq (0)") ('& Lt; div id = "organic-tab" square = "box"> ;);
To work, one of the issues in this code The bunch is. For one, the appentent is not the browser, the grouwer should be: init: function () {gBrowser.addEventListener ( "DOMContentLoaded", myExtension.onPageLoad, True); }, Then, the use of wrappedJSObject is absolutely unnecessary (and the way you do this is also not secure). var Wnd = aEvent.target.defaultView; Var location = wnd.location; Finally, you are trying to select an element in the browser document (the document that is running in your script), not in the document loaded in the tab. You need to give jQuery a clear reference to work:
$ ("# left. Box: eq (0)", wnd.document) But you should not use jQuery like this, it defines many global variables that can fight with other extensions instead of calling you and myExtension : < / P> var myExtension = {$: jQuery.noConflict (true) should call a nickname for a jQuery within .... myExtension. $ ("#left box. Eq (0)", wnd.document)
Comments
Post a Comment