By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,654 Members | 1,580 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,654 IT Pros & Developers. It's quick & easy.

Edit javascript in IE

P: n/a
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

Jul 20 '05 #1
Share this Question
Share on Google+
15 Replies


P: n/a
On Sat, 20 Sep 2003 18:18:27 +0100, bengee
<po********@localhost.localdomain> wrote:
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.


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

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

Jul 20 '05 #2

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


I'll give that a try, thanks.

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

bengee

Jul 20 '05 #3

P: n/a
Ivo
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=open('','edit','top=20,width=650,hei ght='+(screen.availHeight-
99)+',directories,menubar,resizable');d7c=document .documentElement.innerHTML
;d7o=d7c;while(d7c.indexOf('<')>-1)d7c=d7c.replace('<','&lt;');na.document.w
rite('<html><head><title>Sourcedit
"'+document.title+'"</title><style>body{margin:0px;border:0px;font:m
essagebox;background:AppWorkspace}input{font:messa gebox;width:60;}textarea{w
idth:100%;}</style><script>d7o=opener.d7o;onresize=r;onload=r;f unction
r(){f.ta.style.height=document.body.clientHeight-f.ta.offsetTop-1}</script><
/head><body><form name=f><input type=button value=Apply
onclick="opener.document.open();opener.document.wr ite(f.ta.value);opener.doc
ument.close();opener.focus()"><input type=button value=Restore
onclick="f.ta.value=d7o;f.ta.focus()"> Sourcedit <a
href="'+location.href+'">...'+location.href.substr ing(location.href.length-4
0)+'</a> ('+(b=d7o.split('\n').length)+' lines,
'+Math.round(d7o.length/b*10)/10+' cpl)<br><textarea
id=ta>'+d7c+'</textarea></form></body></html>');na.document.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:function JSexe(){ if (valJS!='null' &&
valJS!='undefined')strJS=valJS; strJS=prompt('Your JavaScript code or
variable:',strJS); if (strJS!=null && strJS!='' && strJS!='undefined'){
setTimeout('valJS=\'\'+eval(strJS);JSexe()',10); }
else{valJS='';strJS='';}}valJS='';strJS='';JSexe() ;

HTH
Ivo
www.4umi.com/web/bookmarklet

"bengee" <po********@localhost.localdomain> wrote in message
news:SG********************@wards.force9.net...
Jim Ley wrote:
yep, loads of easy ways, easiest for simple changes on a one of basis
is just to use javascript:yourCode;void 0 - the yourCode will execute
in the context of the page, and the void 0 will stop navigation.


I'll give that a try, thanks.

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

bengee

Jul 20 '05 #4

P: n/a
JRS: In article <SG********************@wards.force9.net>, seen in
news:comp.lang.javascript, bengee <po********@localhost.localdomain>
posted at Sat, 20 Sep 2003 19:07:04 :-
Jim Ley wrote:
yep, loads of easy ways, easiest for simple changes on a one of basis
is just to use javascript:yourCode;void 0 - the yourCode will execute
in the context of the page, and the void 0 will stop navigation.


I'll give that a try, thanks.

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


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.demon.co.uk/> - FAQqish topics, acronyms & links.
PAS EXE TXT ZIP via <URL:http://www.merlyn.demon.co.uk/programs/00index.htm>
My DOS <URL:http://www.merlyn.demon.co.uk/batfiles.htm> - also batprogs.htm.
Jul 20 '05 #5

P: n/a
Dr John Stockton <sp**@merlyn.demon.co.uk> writes:
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.


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 - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #6

P: n/a
Dr John Stockton wrote:
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.


Doctor

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

bengee

Jul 20 '05 #7

P: n/a
Lasse Reichstein Nielsen wrote:
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.


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

bengee

Jul 20 '05 #8

P: n/a
Dr John Stockton wrote:
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.


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

bengee

Jul 20 '05 #9

P: n/a
JRS: In article <r2********************@wards.force9.net>, seen in
news:comp.lang.javascript, bengee <po********@localhost.localdomain>
posted at Sun, 21 Sep 2003 20:34:02 :-
Dr John Stockton wrote:
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.


Doctor

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


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

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

Food expiry ambiguities: <URL:http://www.merlyn.demon.co.uk/date2k-3.htm#Food>
Jul 20 '05 #10

P: n/a
Tom
"bengee" <po********@localhost.localdomain> wrote in message
news:Ly********************@wards.force9.net...
Dr John Stockton wrote:
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.


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

bengee


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=open('','edit','top=20,width=650,hei ght='+(screen.availHeight-
99)+',directories,menubar,resizable');d7c=document .documentElement.innerHTML
;d7o=d7c;while(d7c.indexOf('<')>-1)d7c=d7c.replace('<','&lt;');na.document.w
rite('<html><head><title>Sourcedit
"'+document.title+'"</title><style>body{margin:0px;border:0px;font:m
essagebox;background:AppWorkspace}input{font:messa gebox;width:60;}textarea{w
idth:100%;}</style><script>d7o=opener.d7o;onresize=r;onload=r;f unction
r(){f.ta.style.height=document.body.clientHeight-f.ta.offsetTop-1}</script><
/head><body><form name=f><input type=button value=Apply
onclick="opener.document.open();opener.document.wr ite(f.ta.value);opener.doc
ument.close();opener.focus()"><input type=button value=Restore
onclick="f.ta.value=d7o;f.ta.focus()"> Sourcedit <a
href="'+location.href+'">...'+location.href.substr ing(location.href.length-4
0)+'</a> ('+(b=d7o.split('\n').length)+' lines,
'+Math.round(d7o.length/b*10)/10+' cpl)<br><textarea
id=ta>'+d7c+'</textarea></form></body></html>');na.document.close();na.docum
ent.f.ta.focus();
Jul 20 '05 #11

P: n/a
Tom wrote:
I 'm sure you missed Ivo's post too as you would certainly have replied had
you tried his code. Absolutely BRILLIANT bookmarklet. <snip>


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

Jul 20 '05 #12

P: n/a
Tom

"bengee" <po********@localhost.localdomain> wrote in message
news:2k********************@wards.force9.net...
Tom wrote:
I 'm sure you missed Ivo's post too as you would certainly have replied had you tried his code. Absolutely BRILLIANT bookmarklet. <snip>


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


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
Jul 20 '05 #13

P: n/a
Ivo
"bengee" <po********@localhost.localdomain> wrote in message
news:2k********************@wards.force9.net...
Tom wrote:
I 'm sure you missed Ivo's post too as you would certainly have replied had you tried his code. Absolutely BRILLIANT bookmarklet. <snip>


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


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.documentElement.outerHTML;
while(d7c.indexOf('<')+1)
d7c=d7c.replace('<','&lt;');
na=open('','eW','directories,menubar,resizable');
na.document.write('<form name=f><input type=button value=Apply
onclick="with(opener.document){open();write(docume nt.f.ta.value);close();}op
ener.focus()"><br><textarea id=ta cols=99
rows=32>'+d7c+'</textarea></form>');
na.document.close();
na.document.f.ta.focus();

But no editor can beat the wysiwygs of this one:

javascript:
if(document.body.contentEditable != 'true')
void(document.body.contentEditable = 'true');
else void(document.body.contentEditable = '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=document.getElementsByTagName("SCRIPT");
for(var n=0;n<s.length;n++)
if((r.src=s[n].src))
open("view-source:"+r.src);
s=document.styleSheets;
for(var n=0;n<s.length;n++)
if((r.src=s[n].src))
open("view-source:"+r.src);
open("view-source:"+location.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
Jul 20 '05 #14

P: n/a
JRS: In article <3f***********************@news.wanadoo.nl>, seen in
news:comp.lang.javascript, Ivo <no@thank.you> posted at Sun, 21 Sep 2003
09:02:27 :-
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.

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
"decompressor", 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.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Jul 20 '05 #15

P: n/a
Ivo
"Dr John Stockton" <sp**@merlyn.demon.co.uk> wrote in message
news:VV**************@merlyn.demon.co.uk...
JRS: In article <3f***********************@news.wanadoo.nl>, seen in
news:comp.lang.javascript, Ivo <no@thank.you> posted at Sun, 21 Sep 2003
09:02:27 :-
Follows a bookmarklet that will a page's generated source (that is: the
source including script tags and anything the script may have contibuted tothe 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.


ISTM that the technique, while convenient and ingenious, may be
vulnerable to loss.
(...)
My browser instance was locked, for example, by the posted code of the
"decompressor", 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

Absolutely. Sometimes I want to backup a testpage but not create a whole new
file for it. Remembering to remove that later on is just too much work.
The clipboard is then a most convenient place to temporariliy store the
original code. Not the safest place, and when the test is powerful enough to
crash the computer, things get lost, yes.
Methinks that the weak points of the ideas that have been put forward, are
clear enough, but that the original request aimed for something as simple as
poss, with no intent to save the edited file or opening of other programs.
Sorry, which decompressor code?
Ivo
Jul 20 '05 #16

This discussion thread is closed

Replies have been disabled for this discussion.