944,108 Members | Top Members by Rank

Ad:
Apr 23rd, 2008
0

is it possible to over write internal java script?

Expand Post »
Is it possible to overwrite internal javascript? I am working for a non profit as an internship and they want to escape a template that almost all of the non profits in that organization have to use, the catch is the template is written in Javascript if it is possible to over ride it please tell me as I really need to know ASAP.
Similar Threads
Reputation Points: 48
Solved Threads: 11
Posting Pro
tiger86 is offline Offline
540 posts
since Feb 2008
Apr 24th, 2008
0

Re: is it possible to over write internal java script?

my be this would(i have not tired it). Javascript code are written in <script></script> tags. So search these tags in the document by using: var sTag = document.getElementsByTagName("script"). This will give u an array of script tags. Now over write them by using sTag[0].innerHTML = "your javascript code";


If this work please let me know?
Reputation Points: 83
Solved Threads: 61
Posting Pro in Training
Luckychap is offline Offline
442 posts
since Aug 2006
Apr 24th, 2008
0

Re: is it possible to over write internal java script?

Click to Expand / Collapse  Quote originally posted by Luckychap ...
my be this would(i have not tired it). Javascript code are written in <script></script> tags. So search these tags in the document by using: var sTag = document.getElementsByTagName("script"). This will give u an array of script tags. Now over write them by using sTag[0].innerHTML = "your javascript code";


If this work please let me know?
I am sorry I do not completly understand, are you saying to look in the edocument for the code you listed? If so the code isn't there if you mean something else please pm me or post.
Reputation Points: 48
Solved Threads: 11
Posting Pro
tiger86 is offline Offline
540 posts
since Feb 2008
Apr 29th, 2008
0

Re: is it possible to over write internal java script?

Click to Expand / Collapse  Quote originally posted by tiger86 ...
I am sorry I do not completly understand, are you saying to look in the edocument for the code you listed? If so the code isn't there if you mean something else please pm me or post.
Okay I have searched the whole javascript and they do not use the var command at all they use javascript in a odd way just for images. If there is a way to overwrite it I would be happy and so would my boss.
Reputation Points: 48
Solved Threads: 11
Posting Pro
tiger86 is offline Offline
540 posts
since Feb 2008
Apr 30th, 2008
0

Re: is it possible to over write internal java script?

Hi tiger86, if u can explain ur problem little bit more, i want to know what exactly u want to do.

var is not a command but a way to declare a variable in javascript.

I am explaining my prev. post again, if u still did not get ur problem solved, explain ur problem in detail.

first i want to tell u what i understand from ur post: You want to overwrite the javacript at run-time. if this is correct then my post will help u otherwise explain me ur problem. here is want i explained in prev post. for example u have a page:

html Syntax (Toggle Plain Text)
  1. <html>
  2. <head></head>
  3.  
  4. <body>
  5. <script>
  6. function myfunct() {
  7. //do something
  8. }
  9. </script>
  10.  
  11. </body>
  12. </html>


if u want to change js code in above page,
this a js code todo that :

var tags = document.getElementsByTagName("script");

//Now changing the js code
tags[0].innerHTML = "your new js code should be written here as a string";

again i had not tested it. please let me know how it works?
Last edited by peter_budo; Apr 30th, 2008 at 8:51 am. Reason: Keep It Organized - plase use [code] tags
Reputation Points: 83
Solved Threads: 61
Posting Pro in Training
Luckychap is offline Offline
442 posts
since Aug 2006
Apr 30th, 2008
0

Re: is it possible to over write internal java script?

It works!
Reputation Points: 48
Solved Threads: 11
Posting Pro
tiger86 is offline Offline
540 posts
since Feb 2008
Apr 30th, 2008
0

Re: is it possible to over write internal java script?

the code luckychap posted works but I would not suggest using it unless it is your own website and you are not connected to a national website.
Reputation Points: 48
Solved Threads: 11
Posting Pro
tiger86 is offline Offline
540 posts
since Feb 2008
Nov 10th, 2009
0

A problem with script overwriting

Ok, and what if we have a code like this?
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script src="example.js" type="text/javascript"></script>
In this case, how can we replace the code loaded with example.js?

Let me be more informative. There is this issue on one site - the script it loads via src attribute in script tag is cut down by the server, and instead of having a 362kb successfully loaded script, I've something like 160kb cut one. So I'm trying to write a Greasemonkey userscript, which can overwrite the cut down script with code that it has in itself. For now, I'm not having any success with this problem. Can anyone help me with this?
Last edited by sozeran; Nov 10th, 2009 at 2:24 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sozeran is offline Offline
2 posts
since Nov 2009
Nov 11th, 2009
0
Re: is it possible to over write internal java script?
As I have explained how to get <script> tags. Say we have an array of tags 'scripts'.

javascript Syntax (Toggle Plain Text)
  1. var orginalSrc = "example.js", newSrc = "new.js";
  2. // Looping through all the tags
  3. for(var i = 0; i < scripts.length; i++) {
  4. if(scripts[i].src == originalSrc) {
  5. scripts[i].src = newSrc;
  6. break;
  7. }
  8. }

Is that what u r looking for?
Last edited by Luckychap; Nov 11th, 2009 at 11:40 am.
Reputation Points: 83
Solved Threads: 61
Posting Pro in Training
Luckychap is offline Offline
442 posts
since Aug 2006
Nov 11th, 2009
0
Re: is it possible to over write internal java script?
Click to Expand / Collapse  Quote originally posted by Luckychap ...
As I have explained how to get <script> tags. Say we have an array of tags 'scripts'.

javascript Syntax (Toggle Plain Text)
  1. var orginalSrc = "example.js", newSrc = "new.js";
  2. // Looping through all the tags
  3. for(var i = 0; i < scripts.length; i++) {
  4. if(scripts[i].src == originalSrc) {
  5. scripts[i].src = newSrc;
  6. break;
  7. }
  8. }

Is that what u r looking for?
Will it redefine all the functions introduced in the old script?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sozeran is offline Offline
2 posts
since Nov 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Link with Focus
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Need help building an instant messaging system with AJAX/PHP





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC