Changing content on the fly using JavaScript
Using JavaScript and DHTML, content on your page can be changed dynamically and on-the-fly. Learn how to in this tutorial! You're learn three different techniques, one for IE5, NS4, and NS6.
AI
KI-Zusammenfassung: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Quellcode
<html> <head> <title>Changing content on the fly using DHTML</title> </head> <body> <p><b><font size="4"><u>Changing content on the fly using </u></font></b><b><font size="4"><u>JavaScript/DHTML</u></font></b></p> <p><font size="3">One of my favorite uses of JavaScript, and I guess more specifically, DHTML, is to change content on the fly. Using just a few lines of scripting, I can do away with the slow downloading Java and Flash, and change text even after the page has loaded.</font></p> <p><font size="3">I write this tutorial based on the assumption that you have at least some working knowledge of JavaScript.</font></p> <p>Changing text requires 3 different techniques, depending on the browser. If you're like me, you favor Internet Explorer 5, but the point is that there are always people using other browsers, so we must address them all.</p> <p>Let me first introduce a simple text which I will base my explanations on changing text using:</p> <p><font size="4" face="Courier" color="#008000"><div ID="testing">Planet Source Code</div></font></p> <p>In Internet Explorer 4 or above, the script to change the above text is:</p> <p><font size="3" face="Courier" color="#008000">document.all.testing.innerHTML="A very cool site!"</font></p> <p>I access the text's ID, which tells the script which text I wish to change. Then I use the property .innerHTML, which allows me to change this text to another.</p> <p>In Netscape 6, the idea to alter a text is very similar, except in the precise syntax:</p> <p><font size="3" face="Courier" color="#008000">document.getElementById("testing").innerHTML="A very cool site!"</font></p> <p>Interesting to note is that Internet Explorer 5 also supports this method of changing text. If you don't care about IE4, this one line is sufficient to cover both IE5 and NS6.</p> <p>Finally, we have the dreaded Netscape 4, which surprising is still more popular than NS6. To change text in this browser, I must actually embed the text using a different set of tags (from the DIV). The tags required is:</p> <p><font size="3" face="Courier" color="#008000"><ilayer name="testing"><layer name="testing2">Planet Soure Code</layer></ilayer></font></p> <p>Once the proper tags are setup, I can change its text in Netscape 4 using:</p> <p><font size="3" face="Courier" color="#008000">document.</font><font size="3" face="Courier" color="#008000">testing.document.test2.document.write("A very cool site!")<br> </font><font size="3" face="Courier" color="#008000">document.</font><font size="3" face="Courier" color="#008000">testing.document.test2.document.close()</font></p> <p>Awk! Yes, it's quite messy, but that's the only route to NS4's heart!</p> <p>Many interesting and useful applications can be created by dynamically altering text. I can create a message scroller that changes messages every few seconds, a text that changes when I move my mouse over it, or even an image slide show with a corresponding description beneath it. </p> <p>If you're looking for working examples of changing text on the fly, a good place to start is <a href="http://www.dynamicdrive.com/" target="new">Dynamic Drive</a>.</p> <p>Well, that's it for now. <a href="mailto:[email protected]">Email me</a> if you have any suggestions for new tutorials I can contribute.</p> </body> </html> /* Backwerdz version 1.00 by Miah. It takes a file, reads it from back to front, and outputs it to a new backwards file that can't be read normally. Simple enough... On with the code! */ #include <stdio.h> main() { char fileIn[30], fileOut[30]; char byteBuff[1]; int x=-1, Fsize; printf("\t\t\tMiah's Backwerdz file encoder\n"); printf("\n\nEnter Filename to Encode/Decode: "); scanf("%s",fileIn); printf("\nEnter name to output file as: "); scanf("%s",fileOut); FILE *in, *out; in = fopen(fileIn, "rb"); //Need that "b" so it can read binary too! out = fopen(fileOut, "wb"); //And write it.. fseek(in, 0, SEEK_END); Fsize = ftell(in); //This fTells us the size of the file by going to the end // and reading what the number of the last byte is fseek(in, -1, SEEK_END); //We seek a negative one (-1) from our position at the //end of the file so we read it backwards do { fseek(in, x, SEEK_END); fread(&byteBuff,1,1,in); //read and write at the same time fwrite(&byteBuff,1,1,out); x--; //Continue to countdown Fsize--; //Decrease size count so we can }while(Fsize > 0); //Break the loop when it reaches zero fclose(in); //Close It! fclose(out); return 0; } Upload
Originalkommentare (3)
Wiederhergestellt von der Wayback Machine