add js client side

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Simon

    add js client side

    Is it possible to add a js function to a loaded web page on the client side?
    E.g. IE is viewing google, can I add a javascript function to that instance
    of IE viewing google? I am trying to hook browser events such as button
    clicks and get information such as edit field text.

    Thanks IA, Simon


  • Ivo

    #2
    Re: add js client side

    "Simon" <simbil.nospam. bill@btinternet .please.com> wrote in message
    news:c1n3fr$3ar $1@sparta.btint ernet.com...[color=blue]
    > Is it possible to add a js function to a loaded web page on the client[/color]
    side?[color=blue]
    > E.g. IE is viewing google, can I add a javascript function to that[/color]
    instance[color=blue]
    > of IE viewing google? I am trying to hook browser events such as button
    > clicks and get information such as edit field text.[/color]

    With your webbrowser parked at your preferred google page, type this in the
    addressbar:

    javascript:func tion x(){p=prompt('Y our name...');alert ('Welcome to Google,
    '+p) }; void(x());

    and hit return. You won't leave the page (if you didn't make a typing
    mistake).
    As you can see, you have just added a function called x to the current page.
    It 's the type of scripting upon which bookmarklets are based. It will work
    with any site. But it will only work for that specific copy of the page in
    your browser and only until you leave the page. SO it will only be your own
    clicks that you will be able to monitor.
    And Internet Explorer 6 has reduced support for it: your code should not be
    longer than 208 (or was it 255?) characters or it will be ignored. A
    workaround in modern bookmarklets is to dedicate those 208 characters to
    inserting a .js file on the fly, with something like
    z=document.crea teElement('scri pt');
    z.src="http://mysite.com/myscriptonyours ite.js"
    HTH
    Ivo




    Comment

    • Simon

      #3
      Re: add js client side

      > With your webbrowser parked at your preferred google page, type this in
      the[color=blue]
      > addressbar:
      >
      > javascript:func tion x(){p=prompt('Y our name...');alert ('Welcome to[/color]
      Google,[color=blue]
      > '+p) }; void(x());
      >
      > and hit return. You won't leave the page (if you didn't make a typing
      > mistake).
      > As you can see, you have just added a function called x to the current[/color]
      page.[color=blue]
      > It 's the type of scripting upon which bookmarklets are based.[/color]

      Thanks for that - looks useful. I want to make the process automatic (i.e.
      without typing in the address bar) - any ideas? I guess I can probably hook
      the address bar and update it but I'd rather use a neater method if you know
      of one?

      Simon


      Comment

      • Ivo

        #4
        Re: add js client side

        "Simon" <simbil.nospam. bill@btinternet .please.com> wrote in message
        news:c1nngp$a04 $1@titan.btinte rnet.com...[color=blue][color=green]
        > > With your webbrowser parked at your preferred google page, type this in[/color]
        > the[color=green]
        > > addressbar:
        > >
        > > javascript:func tion x(){p=prompt('Y our name...');alert ('Welcome to[/color]
        > Google,[color=green]
        > > '+p) }; void(x());
        > >
        > > and hit return. You won't leave the page (if you didn't make a typing
        > > mistake).
        > > As you can see, you have just added a function called x to the current[/color]
        > page.[color=green]
        > > It 's the type of scripting upon which bookmarklets are based.[/color]
        >
        > Thanks for that - looks useful. I want to make the process automatic (i.e.
        > without typing in the address bar) - any ideas? I guess I can probably[/color]
        hook[color=blue]
        > the address bar and update it but I'd rather use a neater method if you[/color]
        know[color=blue]
        > of one?
        >
        > Simon[/color]

        I got a present for you, Simon. Like a proper present, you need to carefully
        unwrap it, that is copy and paste each of the following lines in your
        address bar, one after another, without spaces or other noise in between
        (meanwhile, look at the code and guess what is going to happen), so that it
        becomes one line again:

        javascript:void ((function(){va r s='';(function( w){for(var
        i=0;i<w.length; i++){arguments. callee(w.frames[i]);}try{s+=w.doc ument.selecti
        on.createRange( ).text;}catch(e ){try{s+=w.docu ment.getSelecti on();}catch(e){ a
        lert('Bookmarkl et failed:\n\n'+e. message);}}})(t op);if(!s)s=pro mpt('Enter
        keywords:',''); if(s)location=' http://www.google.com/search?q='+esca pe(s);})(
        ))

        If you 're confident all is well, hit return and if you haven't selected any
        text on the current page, you will be prompted for a search query. You can
        save this javascript code in your Favorites, on your Personal Toolbar even,
        if you write it in an <a href="javascrip t:..." tag and bookmark that link.
        There are other, more convenient ways but there re not all easy to explain
        unless bookmarklets tickle your imagination.

        Also see:
        http://www.bookmarklets.com/tools/search/ introduces you to dozens of
        bookmarklets, specifically engineered for faster searching.
        http://www.bookmarklets.com/mk.phtml even has a bookmarklet to helps you in
        creating bookmarklets for any search engines not yet listed.

        HTH
        Ivo


        Comment

        • Simon

          #5
          Re: add js client side

          > I got a present for you, Simon. Like a proper present, you need to
          carefully[color=blue]
          > unwrap it, that is copy and paste each of the following lines in your
          > address bar, one after another, without spaces or other noise in between
          > (meanwhile, look at the code and guess what is going to happen), so that[/color]
          it[color=blue]
          > becomes one line again:
          >
          > javascript:void ((function(){va r s='';(function( w){for(var
          >[/color]
          i=0;i<w.length; i++){arguments. callee(w.frames[i]);}try{s+=w.doc ument.selecti[color=blue]
          >[/color]
          on.createRange( ).text;}catch(e ){try{s+=w.docu ment.getSelecti on();}catch(e){ a[color=blue]
          > lert('Bookmarkl et failed:\n\n'+e. message);}}})(t op);if(!s)s=pro mpt('Enter
          >[/color]
          keywords:',''); if(s)location=' http://www.google.com/search?q='+esca pe(s);})([color=blue]
          > ))
          >[/color]

          Thanks - that's cool :)
          Is there a way that a bookmarklet can be run with a link. For example, some
          PC has a link that points to a web app - something like http://192.168.1.22.
          Can the bookmarklet be appended to the link somehow so that the web site
          opens and the bookmarklet runs?
          [color=blue]
          > Also see:
          > http://www.bookmarklets.com/tools/search/ introduces you to dozens of
          > bookmarklets, specifically engineered for faster searching.
          > http://www.bookmarklets.com/mk.phtml even has a bookmarklet to helps you[/color]
          in[color=blue]
          > creating bookmarklets for any search engines not yet listed.
          >[/color]

          I had a look at those and also http://tantek.com favelet - I'll need to
          study them for a while.

          Simon


          Comment

          Working...