views:

61

answers:

1

I've included jQuery by doing this:

<?xml version="1.0"?>
<!DOCTYPE window SYSTEM "chrome://orkutmanager/locale/browser.dtd">
    <overlay id="omcore" 
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"&gt;

    <script type="application/x-javascript" src="../../jquery-1.4.2.js"/>
    <script type="text/javascript">jQuery.noConflict();</script>

    <script type="application/x-javascript" src="../../OM.js"/>

</overlay>

Here is my chrome.manifest

content orkutmanager    chrome/content/
overlay chrome://browser/content/browser.xul chrome://orkutmanager/content/XUL/Browser/Core.xul

skin orkutmanager classic skin/

locale orkutmanager en-US locale/en-US/

And then I tried to use

gBrowser.addEventListener('DOMContentLoaded',
    function (e)
    {
        var contentWindow = e.originalTarget.defaultView;
        var contentDocument = contentWindow.document;

        var $ = jQuery;

        var x = $("a", contentDocument).attr("onclick"); //
        // Error: uncaught exception: unknown (can't convert to string)

    }, false);

While

$("a", contentDocument).get(0).getAttribute("onclick");

Works normal.

Do I have to include jQuery in a different way? How can I make it work as usual? Is there another jQuery method to get the value of an attribute?

On a normal case it works, example here.

A: 

You are accessing the onclick property using the attr function.

The docs say nothing about it, but could it be that attr() forces its return value into a string? It looks like it.

What if you access onclick directly? What are you doing with it?

Pekka
I just tried `$('<a onclick="123;"></a>').attr('onclick');` and got no such error.
J-P
Sounds reasonable. Anyway the OP mixes native javascript / DOM events / jQuery in a questionable way. @J-P: That statement is really worth not much without browser/version.
jAndy
But it's `<a onclick="something"></a>`. How should I get this attribute then? The only way would be `get(0).getAttribute` ?
BrunoLM
Directly? `$("a").onclick` is undefined. I've added one example http://jsfiddle.net/PJ4F5/ . I wanted only the string though, but that would be enough
BrunoLM
@BrunoLM - You can't use `document.write` in a `window.onload` like that, instead append it to the body...also the function needs to be defined, like this: http://jsfiddle.net/PJ4F5/1/
Nick Craver
Doesn't matter if the function works or not, I just want to retrieve `_link(...)` from the attribute. But on the addon it doesn't work and on jsfiddle it return `function (event) { ... }`...
BrunoLM
I guess then the answer is that jQuery doesn't support this attribute? I will need to make a plugin for it?
BrunoLM
@BrunoLM - It's not exactly an attribute...it's an event, a handler rigged up via markup, here's an even *smaller* example showing it works: http://jsfiddle.net/PJ4F5/2/
Nick Craver