Cookie editor bookmarklet

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jesper Rønn-Jensen

    Cookie editor bookmarklet

    Hi everybody.
    I just created a bookmarklet that can view, add and edit cookies.
    Feel free to use it, if you like. And please share any modifications
    you make.

    I had a hard time figuring out exactly which characters are allowed.
    For instance, i _think_ the equal sign (=) is allowed even though it
    has special meaning in the cookie string.

    The bookmarklet creates a popup window and loads a javascript file from
    my webserver.

    I really appreciate any comments/feedback/suggestions.
    For now, I have tried it in Firefox 1.0.1 and IE6 /windows

    javascript:(fun ction(){u='http ://visitjesper.hom eip.net/cookieeditor.js ';w=window.open ();w.document.w rite('<html><he ad></head><body></body></html>');w.docum ent.close();s=w .document.body. appendChild(w.d ocument.createE lement('script' ));s.type='text/javascript';s.s rc=u;})()


    Kind regards,
    Jesper

  • Ivo

    #2
    Re: Cookie editor bookmarklet

    "Jesper Rønn-Jensen" wrote[color=blue]
    >[/color]
    javascript:(fun ction(){u='http ://visitjesper.hom eip.net/cookieeditor.js ';w=w
    indow.open();w. document.write( '<html><head></head><body></body></html>');w.d
    ocument.close() ;s=w.document.b ody.appendChild (w.document.cre ateElement('scr i
    pt'));s.type='t ext/javascript';s.s rc=u;})()

    Well, encapsulating your statements in a function is rather nice but also
    quite pointless if you don't initialize the variables using the "var"
    keyword. Because now they still end up being global variables which is never
    a good idea and certainly not in bookmarklet that need to adept to any and
    all pages that may well have their own global variables that you don't want
    to interfere with.
    The url to your .js file is in a variable "u" that you use only once, why
    not assign it directly to "s.src"? And why mix document.write( ) and
    document.create Element()? Also, when writing HTML with javascript, the
    closing tags should look like this:

    <\/tag>

    with a backslash escaping the slash. It may not break the script in all
    cases if you don't, but it never hurts so it 's best to get used to it. A
    parser might think the script section has ended when it encounters the
    string "</" without backslash, ending your script prematurely.
    --
    Ivo







    Comment

    • Jesper Rønn-Jensen

      #3
      Re: Cookie editor bookmarklet

      Thanks for your response. Good points about declaring my variables with
      'var'.


      Jesper

      Comment

      Working...