Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can you use DOM to change/add javascript?

Status
Not open for further replies.

pcawdron

Programmer
Jun 14, 2000
109
AU
This is another way of solving the same problem I raised as createElement('SCRIPT').... in essence, can you use DOM to change a script, or add a script? Consider the following


<html>
<body>
<script language=&quot;javascript&quot; id=&quot;jTest&quot;>
alert(&quot;hi&quot;)
</script>
<a href=&quot;javascript:ChangeScript()&quot;>Click Here to change your javascript</a>
<script language=&quot;javascript&quot;>
function ChangeScript(){
alert(jTest.innerHTML);
var NewScript = document.createTextNode(&quot;alert('how are you')&quot;);
jTest.appendChild(NewScript) ;
//...I've even tried....
//jTest.innerHTML=&quot;alert('how are you')&quot;
//...but that doesn't work either....
alert(jTest.innerHTML);
}
</script>
</body>
</html>


Any ideas why it doesn't work? Or how I can use DOM to add a script?

Thanks,
Peter
 
I tried, got &quot;Unknown runtime error&quot; (IE 5.5) on the line that changes script contents. Probably shouldn't be much of a surprise. I'd imagine the browser's got lots of special stuff to do when loading script, may be easier if it can assume a blank slate.

What are you looking to do? Scripting already allows you to change display content, install and update variables and objects. What practical advantage does the capability to alter script give you? (Stealth is the only benefit I can come up with.)


Wray

The wheel wasn't reinvented in a day.
 
I want to develop a JavaScript IDE....

As an old VB programmer, I am partial to working in a programming environment where as you type you can see all the properties, methods, events available to you for each object. My thinking is, why hasn't anyone done something like this for javascript? (A language that is purely object oriented, where VB is just a hybrid OO language) And, why not do it as an on-line editor?

I've built a small, on-line HTML editor that allows you to enter HTML in to a textarea and, as you type, the results are displayed immediately in another DIV as HTML. Works fine for HTML, but not Scripts....

My editor has three DIV areas, one where you type your HTML, the second shows a tree containing all the properties, methods and events available for each element/object, and the third showing the results.

Thanks for your input, it's most appreciated...

 
It is strange isn't it? Symbiotically attached to the most powerful information rendering device of human history, one debugs JavaScript exactly the same way one debugs Dartmouth BASIC -- by inserting print statements at critical points. I'm sure Microsoft has studied this situation and we can probably infer that the solution costs more than it will sell for.

eval() gives you the ability in JavaScript to communicate with the JavaScript interpreter at runtime. You may be able to move forward by using eval(&quot;alert('hello world')&quot;) to emulate JavaScript. There has to be some enormous challenges but what the hey ...

Good luck and Godspeed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top