Edit javascript in IE

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

    Edit javascript in IE

    Hi

    Does anyone know of a way to edit "live" javascript (that i have no
    control over) in IE?

    Example, i visit a website and see a webpage in IE containing
    Javascript. Can i edit that javascript and get IE to accept any changes
    i've done to it?

    So what i'm saying really, is that i want to hack the javascript served
    to me from a website.

    Ben

  • Jim Ley

    #2
    Re: Edit javascript in IE

    On Sat, 20 Sep 2003 18:18:27 +0100, bengee
    <postmaster@loc alhost.localdom ain> wrote:
    [color=blue]
    >Example, i visit a website and see a webpage in IE containing
    >Javascript. Can i edit that javascript and get IE to accept any changes
    >i've done to it?
    >
    >So what i'm saying really, is that i want to hack the javascript served
    >to me from a website.[/color]

    yep, loads of easy ways, easiest for simple changes on a one of basis
    is just to use javascript:your Code;void 0 - the yourCode will execute
    in the context of the page, and the void 0 will stop navigation.

    Jim.
    --
    comp.lang.javas cript FAQ - http://jibbering.com/faq/

    Comment

    • bengee

      #3
      Re: Edit javascript in IE

      Jim Ley wrote:[color=blue]
      > yep, loads of easy ways, easiest for simple changes on a one of basis
      > is just to use javascript:your Code;void 0 - the yourCode will execute
      > in the context of the page, and the void 0 will stop navigation.[/color]

      I'll give that a try, thanks.

      Anyway's to edit the actual code in a text editor or similar?

      bengee

      Comment

      • Ivo

        #4
        Re: Edit javascript in IE

        Follows a bookmarklet that will a page's generated source (that is: the
        source including script tags and anything the script may have contibuted to
        the page) in a new window which has
        1. a textarea where you can edit the code
        2. an button "Apply" that overwrites the page with your edited version.
        3. a "Restore" button that will attempt to, eh, restore the old page.

        This the code (bookmarklet code should be all on one line):
        javascript:na=o pen('','edit',' top=20,width=65 0,height='+(scr een.availHeight-
        99)+',directori es,menubar,resi zable');d7c=doc ument.documentE lement.innerHTM L
        ;d7o=d7c;while( d7c.indexOf('<' )>-1)d7c=d7c.repla ce('<','&lt;'); na.document.w
        rite('<html><he ad><title>Sourc edit
        &#34;'+document .title+'&#34;</title><style>bo dy{margin:0px;b order:0px;font: m
        essagebox;backg round:AppWorksp ace}input{font: messagebox;widt h:60;}textarea{ w
        idth:100%;}</style><script>d 7o=opener.d7o;o nresize=r;onloa d=r;function
        r(){f.ta.style. height=document .body.clientHei ght-f.ta.offsetTop-1}</script><
        /head><body><for m name=f><input type=button value=Apply
        onclick="opener .document.open( );opener.docume nt.write(f.ta.v alue);opener.do c
        ument.close();o pener.focus()"> <input type=button value=Restore
        onclick="f.ta.v alue=d7o;f.ta.f ocus()"> Sourcedit <a
        href="'+locatio n.href+'">...'+ location.href.s ubstring(locati on.href.length-4
        0)+'</a> ('+(b=d7o.split ('\n').length)+ ' lines,
        '+Math.round(d7 o.length/b*10)/10+' cpl)<br><textar ea
        id=ta>'+d7c+'</textarea></form></body></html>');na.docu ment.close();na .docum
        ent.f.ta.focus( );


        Follows a bookmarklet that will prompt for a javascript expression. For
        example if you know a page uses a global variable called "myVar", simply
        type myVar in the prompt and the current value will be returned. Or if you
        wish to change a function called "myFunc", enter function myFunc(){/* new
        code */} and myFunc will behave in the new way from then on.

        This is the code:
        javascript:func tion JSexe(){ if (valJS!='null' &&
        valJS!='undefin ed')strJS=valJS ; strJS=prompt('Y our JavaScript code or
        variable:',strJ S); if (strJS!=null && strJS!='' && strJS!='undefin ed'){
        setTimeout('val JS=\'\'+eval(st rJS);JSexe()',1 0); }
        else{valJS='';s trJS='';}}valJS ='';strJS='';JS exe();

        HTH
        Ivo


        "bengee" <postmaster@loc alhost.localdom ain> wrote in message
        news:SG0bb.8157 $vX3.1282694@wa rds.force9.net. ..[color=blue]
        > Jim Ley wrote:[color=green]
        > > yep, loads of easy ways, easiest for simple changes on a one of basis
        > > is just to use javascript:your Code;void 0 - the yourCode will execute
        > > in the context of the page, and the void 0 will stop navigation.[/color]
        >
        > I'll give that a try, thanks.
        >
        > Anyway's to edit the actual code in a text editor or similar?
        >
        > bengee
        >[/color]


        Comment

        • Dr John Stockton

          #5
          Re: Edit javascript in IE

          JRS: In article <SG0bb.8157$vX3 .1282694@wards. force9.net>, seen in
          news:comp.lang. javascript, bengee <postmaster@loc alhost.localdom ain>
          posted at Sat, 20 Sep 2003 19:07:04 :-[color=blue]
          >Jim Ley wrote:[color=green]
          >> yep, loads of easy ways, easiest for simple changes on a one of basis
          >> is just to use javascript:your Code;void 0 - the yourCode will execute
          >> in the context of the page, and the void 0 will stop navigation.[/color]
          >
          >I'll give that a try, thanks.
          >
          >Anyway's to edit the actual code in a text editor or similar?[/color]

          For me, View Source shows a copy in Notepad; then use Notepad Save As so
          that you can work on the copy in a well-chosen location on disc. To
          view it, enter location in browser address bar.

          Or use browser Save As, and find it with your preferred editor.

          --
          © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk DOS 3.3, 6.20; Win98. ©
          Web <URL:http://www.merlyn.demo n.co.uk/> - FAQqish topics, acronyms & links.
          PAS EXE TXT ZIP via <URL:http://www.merlyn.demo n.co.uk/programs/00index.htm>
          My DOS <URL:http://www.merlyn.demo n.co.uk/batfiles.htm> - also batprogs.htm.

          Comment

          • Lasse Reichstein Nielsen

            #6
            Re: Edit javascript in IE

            Dr John Stockton <spam@merlyn.de mon.co.uk> writes:
            [color=blue]
            > For me, View Source shows a copy in Notepad; then use Notepad Save As so
            > that you can work on the copy in a well-chosen location on disc. To
            > view it, enter location in browser address bar.[/color]

            One of the things I like about Opera, is that view source lets me edit
            the source (with, e.g., notepad) directly in the cache. If I make a change
            and refresh the page, I see the change in action, while pressing reload
            gets the source from the server again.

            -L
            --
            Lasse Reichstein Nielsen - lrn@hotpop.com
            Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
            'Faith without judgement merely degrades the spirit divine.'

            Comment

            • bengee

              #7
              Re: Edit javascript in IE

              Dr John Stockton wrote:[color=blue]
              > For me, View Source shows a copy in Notepad; then use Notepad Save As so
              > that you can work on the copy in a well-chosen location on disc. To
              > view it, enter location in browser address bar.
              >
              > Or use browser Save As, and find it with your preferred editor.[/color]

              Doctor

              I need to be able to "reload" the javascript back into IE (website only
              supports IE :-(

              bengee

              Comment

              • bengee

                #8
                Re: Edit javascript in IE

                Lasse Reichstein Nielsen wrote:[color=blue]
                > One of the things I like about Opera, is that view source lets me edit
                > the source (with, e.g., notepad) directly in the cache. If I make a change
                > and refresh the page, I see the change in action, while pressing reload
                > gets the source from the server again.[/color]

                This sounds like exactly the thing i need, trouble is that the website i
                need to access only supports IE :-(

                bengee

                Comment

                • bengee

                  #9
                  Re: Edit javascript in IE

                  Dr John Stockton wrote:[color=blue]
                  > For me, View Source shows a copy in Notepad; then use Notepad Save As so
                  > that you can work on the copy in a well-chosen location on disc. To
                  > view it, enter location in browser address bar.[/color]

                  Duh, i didn't fully read your post John. I'll give that a try :-)

                  bengee

                  Comment

                  • Dr John Stockton

                    #10
                    Re: Edit javascript in IE

                    JRS: In article <r2nbb.8571$vX3 .1407276@wards. force9.net>, seen in
                    news:comp.lang. javascript, bengee <postmaster@loc alhost.localdom ain>
                    posted at Sun, 21 Sep 2003 20:34:02 :-[color=blue]
                    >Dr John Stockton wrote:[color=green]
                    >> For me, View Source shows a copy in Notepad; then use Notepad Save As so
                    >> that you can work on the copy in a well-chosen location on disc. To
                    >> view it, enter location in browser address bar.
                    >>
                    >> Or use browser Save As, and find it with your preferred editor.[/color]
                    >
                    >Doctor
                    >
                    >I need to be able to "reload" the javascript back into IE (website only
                    >supports IE :-([/color]

                    That's reasonable, which is why I told you how to do it.

                    --
                    © John Stockton, Surrey, UK. ???@merlyn.demo n.co.uk Turnpike v4.00 MIME. ©
                    Web <URL:http://www.merlyn.demo n.co.uk/> - FAQish topics, acronyms, & links.

                    Food expiry ambiguities: <URL:http://www.merlyn.demo n.co.uk/date2k-3.htm#Food>

                    Comment

                    • Tom

                      #11
                      Re: Edit javascript in IE

                      "bengee" <postmaster@loc alhost.localdom ain> wrote in message
                      news:Lypbb.8657 $vX3.1429605@wa rds.force9.net. ..[color=blue]
                      > Dr John Stockton wrote:[color=green]
                      > > For me, View Source shows a copy in Notepad; then use Notepad Save As so
                      > > that you can work on the copy in a well-chosen location on disc. To
                      > > view it, enter location in browser address bar.[/color]
                      >
                      > Duh, i didn't fully read your post John. I'll give that a try :-)
                      >
                      > bengee[/color]

                      I 'm sure you missed Ivo's post too as you would certainly have replied had
                      you tried his code. Absolutely BRILLIANT bookmarklet. I 've been dreaming
                      about such a thing for years. No need for Notepad or any other application.
                      Edit the page right there and then in your browser, script, style, anything,
                      and see the page change almost as you type! The style tags aren't really
                      necessary I believe, so cut them out if you like. Here is the code again:

                      This the code (bookmarklet code should be all on one line):
                      javascript:na=o pen('','edit',' top=20,width=65 0,height='+(scr een.availHeight-
                      99)+',directori es,menubar,resi zable');d7c=doc ument.documentE lement.innerHTM L
                      ;d7o=d7c;while( d7c.indexOf('<' )>-1)d7c=d7c.repla ce('<','&lt;'); na.document.w
                      rite('<html><he ad><title>Sourc edit
                      &#34;'+document .title+'&#34;</title><style>bo dy{margin:0px;b order:0px;font: m
                      essagebox;backg round:AppWorksp ace}input{font: messagebox;widt h:60;}textarea{ w
                      idth:100%;}</style><script>d 7o=opener.d7o;o nresize=r;onloa d=r;function
                      r(){f.ta.style. height=document .body.clientHei ght-f.ta.offsetTop-1}</script><
                      /head><body><for m name=f><input type=button value=Apply
                      onclick="opener .document.open( );opener.docume nt.write(f.ta.v alue);opener.do c
                      ument.close();o pener.focus()"> <input type=button value=Restore
                      onclick="f.ta.v alue=d7o;f.ta.f ocus()"> Sourcedit <a
                      href="'+locatio n.href+'">...'+ location.href.s ubstring(locati on.href.length-4
                      0)+'</a> ('+(b=d7o.split ('\n').length)+ ' lines,
                      '+Math.round(d7 o.length/b*10)/10+' cpl)<br><textar ea
                      id=ta>'+d7c+'</textarea></form></body></html>');na.docu ment.close();na .docum
                      ent.f.ta.focus( );


                      Comment

                      • bengee

                        #12
                        Re: Edit javascript in IE

                        Tom wrote:[color=blue]
                        > I 'm sure you missed Ivo's post too as you would certainly have replied had
                        > you tried his code. Absolutely BRILLIANT bookmarklet. <snip>[/color]

                        Tried Ivo's 2 bookmarklets. The 1st (big) one doesn't work. 2nd one ok
                        though. What version of IE are you using Tom and Ivo?

                        bengee

                        Comment

                        • Tom

                          #13
                          Re: Edit javascript in IE


                          "bengee" <postmaster@loc alhost.localdom ain> wrote in message
                          news:2kqbb.8670 $vX3.1433121@wa rds.force9.net. ..[color=blue]
                          > Tom wrote:[color=green]
                          > > I 'm sure you missed Ivo's post too as you would certainly have replied[/color][/color]
                          had[color=blue][color=green]
                          > > you tried his code. Absolutely BRILLIANT bookmarklet. <snip>[/color]
                          >
                          > Tried Ivo's 2 bookmarklets. The 1st (big) one doesn't work. 2nd one ok
                          > though. What version of IE are you using Tom and Ivo?
                          >
                          > bengee[/color]

                          I use IE6 on Windows XP. I had to shorten the code to make it work. That is
                          why I mentioned the style tags. With IE6 's diminished support for
                          bookmarklets, bookmarklet code should be kept to an *absolute* minimum.
                          Tom


                          Comment

                          • Ivo

                            #14
                            Re: Edit javascript in IE

                            "bengee" <postmaster@loc alhost.localdom ain> wrote in message
                            news:2kqbb.8670 $vX3.1433121@wa rds.force9.net. ..[color=blue]
                            > Tom wrote:[color=green]
                            > > I 'm sure you missed Ivo's post too as you would certainly have replied[/color][/color]
                            had[color=blue][color=green]
                            > > you tried his code. Absolutely BRILLIANT bookmarklet. <snip>[/color]
                            >
                            > Tried Ivo's 2 bookmarklets. The 1st (big) one doesn't work. 2nd one ok
                            > though. What version of IE are you using Tom and Ivo?
                            >
                            > bengee[/color]

                            There seems to be an error in that code, I 've heard it before, but nobody
                            's found it yet.
                            IE5.5 on WinME has no problems, as far as my machine goes.
                            Here is a stripped down version:

                            javascript:
                            d7c=document.do cumentElement.o uterHTML;
                            while(d7c.index Of('<')+1)
                            d7c=d7c.replace ('<','&lt;');
                            na=open('','eW' ,'directories,m enubar,resizabl e');
                            na.document.wri te('<form name=f><input type=button value=Apply
                            onclick="with(o pener.document) {open();write(d ocument.f.ta.va lue);close();}o p
                            ener.focus()">< br><textarea id=ta cols=99
                            rows=32>'+d7c+' </textarea></form>');
                            na.document.clo se();
                            na.document.f.t a.focus();

                            But no editor can beat the wysiwygs of this one:

                            javascript:
                            if(document.bod y.contentEditab le != 'true')
                            void(document.b ody.contentEdit able = 'true');
                            else void(document.b ody.contentEdit able = 'false');

                            A problem not solved by the suggestions sofar in this thread involves
                            external js and css. A bookmarklet to pop up as many Notepads as there are
                            external scripts and styles on a page, plus one for the page source itself,
                            is as follows:

                            javascript:
                            var r=new Image(),s=docum ent.getElements ByTagName("SCRI PT");
                            for(var n=0;n<s.length; n++)
                            if((r.src=s[n].src))
                            open("view-source:"+r.src) ;
                            s=document.styl eSheets;
                            for(var n=0;n<s.length; n++)
                            if((r.src=s[n].src))
                            open("view-source:"+r.src) ;
                            open("view-source:"+locati on.href);
                            void('Free Mumia Abu-Jamal!');

                            And all on one line.
                            www.4umi.com/bookmarklet/edit.htm is an online, well the url sais it all.
                            One click of the mouse will compress the code to a single line, or format it
                            with indentation as shown above, after some basic validation. Some more
                            advanced functions, such as find-n-replace, are still in beta, and IE only
                            until other browsers learn proper textrange handling. I need to break the
                            problems down, then I can post some code here for the whoever to chew on.
                            I wish to claim none of this code as my own, everything is cut-n-pasted
                            together.
                            Ivo


                            Comment

                            • Dr John Stockton

                              #15
                              Re: Edit javascript in IE

                              JRS: In article <3f6d4c72$0$348 95$1b62eedf@new s.wanadoo.nl>, seen in
                              news:comp.lang. javascript, Ivo <no@thank.you > posted at Sun, 21 Sep 2003
                              09:02:27 :-[color=blue]
                              >Follows a bookmarklet that will a page's generated source (that is: the
                              >source including script tags and anything the script may have contibuted to
                              >the page) in a new window which has
                              >1. a textarea where you can edit the code
                              >2. an button "Apply" that overwrites the page with your edited version.
                              >3. a "Restore" button that will attempt to, eh, restore the old page.[/color]


                              ISTM that the technique, while convenient and ingenious, may be
                              vulnerable to loss.

                              If the revised page is saved to disc, then that is as safe as anything
                              can be on such a computer (still vulnerable to burglary, fire, ...).

                              But it seems that editing-in-place will be vulnerable to anything that
                              crashes or locks up the browser, including errors in editing.

                              My browser instance was locked, for example, by the posted code of the
                              "decompress or", perhaps because I'd failed to spot a line-wrap. Other
                              instances kept running, but all died when I tried to kill the locked
                              one.

                              --
                              © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
                              <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
                              <URL:http://www.merlyn.demo n.co.uk/js-index.htm> JS maths, dates, sources.
                              <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.

                              Comment

                              Working...