greasemonkey specific javascript irregularities

Discussion in 'Javascript' started by bosky101@gmail.com, Jun 4, 2006.

  1. Guest

    alright ive heard a lot about the onclick being needing to be replaced
    with click ,and some other healthy practices like that . but im still
    not able to figure out the problem . my click event is not triggered .
    no error shown in javascript console as well . any idea ?

    // JavaScript Document
    window.addEventListener("load", function() {
    var i=0;
    draw();

    function draw(){
    var t = document.createElement("div");
    t.innerHTML = "<div id=\"div1\" style=\"margin: 0 auto 0
    auto;\"><input name=\"submit\" type=\"submit\" id='btnStart'
    value=\"Start\"></div>";
    document.body.insertBefore(t, document.body.firstChild);
    document.getElementById('btnStart').setAttribute("click",
    function()
    {start()},false);
    }

    function start(){
    alert('started');
    }

    },false);

    the div1 is shown, but events are not triggered . sometimes i get a
    funciton not defined as well.

    Keep Clicking,
    Bosky
     
    , Jun 4, 2006
    #1
    1. Advertising

  2. wrote:


    > document.getElementById('btnStart').setAttribute("click",
    > function()
    > {start()},false);



    I think you want
    document.getElementById('btnStart').addEventListener("click",
    function()
    {start()},false);

    Using setAttribute with a function argument and a third argument does
    not make sense with Mozilla/Firefox and Greasemonkey scripts.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jun 4, 2006
    #2
    1. Advertising

  3. wrote in news: in
    comp.lang.javascript:

    > alright ive heard a lot about the onclick being needing to be replaced
    > with click


    [snip]

    > document.getElementById('btnStart').setAttribute("click",
    > function()
    > {start()},false);



    document.getElementById('btnStart').addEventListener(
    "click",
    function() {start()},
    false
    );

    The event is called "click" the attribute is called "onclick".

    Either of:

    document.getElementById('btnStart').onclick = function() {start()};
    document.getElementById('btnStart').setAttribute(
    "onclick",
    "alert('started');"
    );

    Will also work.

    > }
    >
    > function start(){
    > alert('started');
    > }
    >
    > },false);
    >


    Rob.
    --
    http://www.victim-prime.dsl.pipex.com/
     
    Rob Williscroft, Jun 4, 2006
    #3
  4. Guest


    >> thanks guys ...


    now ive come across one more problem .the dreaded 'permissions' denial
    ..

    i have the folowing two lines appended in prefs.js:
    user_pref("capability.principal.codebase.p0.granted",
    "UniversalBrowserRead");
    user_pref("signed.applets.codebase_principal_support", true);

    the ajax calls in my greasemonkey code goes as follows :

    if (window.XMLHttpRequest)
    { //FF
    setSecurity();
    req = new XMLHttpRequest();
    [snip]
    ..
    ..
    ..

    [/snip]
    setSecurity();
    req.open("GET", dest, true);
    [snip/]

    function setSecurity(){
    try {
    netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
    netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserWrite");
    }
    catch (e) {
    alert('Permission UniversalBrowserRead denied.');
    }
    }

    now when i embed this code in html it works well. i still get the
    Permission UniversalBrowserRead denied. message (exception caught) .
    where am i going wrong ?

    Thanks again ...
    - Bhasker
     
    , Jun 4, 2006
    #4
  5. Guest

    1) actaully i seem to be getting a 'netscape is not defined' message in
    my exception. bugzilla.mozilla.org/show_bug.cgi?id=35116 says that
    changing prefs.js ,and then restarting firefox will give the 'netscape
    is not defined' message. but i kept restarting FF . still no luck.

    2)searching on the 'right' methods to apply privileges in firefox (
    without signing ),i came across
    http://almaer.com/blog/archives/cat_tech.html that says that :

    function securePrivilege(priv) {
    // insert the try/catch code from above, plus anything for the
    other browsers
    }

    and then calling securePrivilege('UniversalBrowserRead') WILL NOT WORK
    at all !... the privilege that you secure, is only applied in that
    scope. This means that the priviledge is only even around INSIDE
    securePrivilege(priv), and is thus useless " .... IS this true ?

    2) does that mean that the FOLLOWING also will not work since its in a
    if/else scope?! :

    if (typeof netscape != 'undefined' && typeof netscape.security
    !='undefined') {
    try
    {
    netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserRead');}catch(e){alert(e.message);}
    }

    else{ alert(e.message);}
    req.open("GET", dest, true);
    ..
    ..

    3) i also tried avoiding the priveleges line ,and simply depending on
    appending a user_pref("signed.applets.codebase_principal_support",
    true); in prefs.js . it STILL dint work .

    4)most of the tutorials and guides give incomplete implementations and
    just say add a line ,and presto! it shud work . does anyone have a
    working example including the xmlhttprequest calls ,and WHERE EXACTLY
    to call the privilege setting lines ?

    Keep Clicking,
    bosky
     
    , Jun 4, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Adrian Holovaty

    ANN: Greasemonkey compiler

    Adrian Holovaty, Apr 27, 2005, in forum: Python
    Replies:
    0
    Views:
    369
    Adrian Holovaty
    Apr 27, 2005
  2. why the lucky stiff
    Replies:
    1
    Views:
    222
    Phil Tomson
    Aug 30, 2005
  3. Lachie
    Replies:
    1
    Views:
    104
    Adam Keys
    Mar 24, 2006
  4. Newton
    Replies:
    2
    Views:
    342
    Lasse Reichstein Nielsen
    Sep 21, 2005
  5. Brantley Harris

    Irregularities in Regular Expressions

    Brantley Harris, Aug 20, 2009, in forum: Javascript
    Replies:
    1
    Views:
    69
    Thomas 'PointedEars' Lahn
    Aug 20, 2009
Loading...

Share This Page