I was trying to implement the Konami Code on my website, utilizing the simple konami-js project on google code. When I try to insert a document.write command into the code, like so: <script type="text/javascript" src="http://konami-js.googlecode.com/svn/trunk/konami.js"></script> <script type="text/javascript"> konami = new Konami() konami.code = function() { document.write("Hello, World!") } konami.load() </script> Code (markup): it loads a new page with only the text "Hello, World" on it. How might I just have it print that text within the HTML, instead of a new page? Is anyone familiar with this script, or could you please look through it to see why this is happening? By the way, here is a direct link to the konami-js code. Thank you
You're not doing anything wrong - that's just the nature of document.write(). When you call document.write() after the page has already loaded, it will replace the current page content with whatever you specify. I'd suggest looking into the following - Try redirecting the user to a different page that has the content you want. I believe that's shown in the Konami-JS example - Look into using a JavaScript library such as jQuery that have easy-to-use functions for appending content to the page that will work across all browsers. That should help. ~ George
Wow, I didn't expect the writer of the original code! Well, thank you, that did help. Now I just have to find one of those functions, so far to no avail. Well, I'm sure I'll find one eventually. Maybe I'll just go for rewriting the whole thing in Python, a language I know.
Not that surprising really, this thread is already on the first page of Google for "konami-js". Try this out: <html> <head> <script type="text/javascript" src="konami.js"></script> <script type="text/javascript"> function startKonami() { var konami = new Konami(); konami.code = function() { document.getElementById("konami").innerHTML = "<span style='color:red;'>You are a Konami fan!</span>"; } konami.load(); } </script> </head> <body onload="startKonami();"> <span id="konami">You are not a Konami fan</span> </body> </html> Code (markup): Up, Up, Down, Down, Left, Right, Left, Right, A......damn it!
Thanks, but that didn't work . The "innerHTML" function is something I tried earlier, but couldn't get to work.