Click to See Complete Forum and Search --> : scripting in scripting
SearedIce
06-11-2003, 11:59 AM
in something like:
document.innerHTML = "hahahahaha";
how would i put a javascript script within the "" (where the 'hahahahaha' is now)?
when i do like:
<script language="Javascript">
document.innerHTML = "<script language='javascript'>alert('haha');</script>";
</script>
internet explorer thinks the </script> within the quotes is the </script> for the whole thing, and it prints out "; on my page
how can i put a javascript in the quotes?
i can't even do a <script langauge='javascript' src='haha.js'> because that too requires a </script> to run
~John
AdamBrill
06-11-2003, 12:00 PM
It would be like this:
<script language="Javascript">
document.innerHTML = "<script language='javascript'>alert('haha');</script\>";
</script>
SearedIce
06-11-2003, 12:05 PM
that's not working...or at least its not giving me my alert
~John
SearedIce
06-11-2003, 12:40 PM
well...at least it does not think that it is the end of the full script...
but it still won't work...anyone else have any other ideas?
It's because it thinks you're closing the current <script> tag. Try this:
<script language="Javascript">
document.innerHTML = "<scri"+"pt language='javascript'\>alert('haha');<\/sc"+"ript\>";
</script>
Although I would think that you should just simply add another line: alert('haha'); to the current Javascript..
Jona
SearedIce
06-11-2003, 12:45 PM
nope that isn't working either :( :(
and as for simply adding the alert("haha"); to the normal script:
this is hypothetical and i'm using the results for another scenario...
SearedIce
06-11-2003, 12:52 PM
it doesn't work as-is but i just tried it in a document.write and it works...i'll now try it in my situation
Using document.write() will overwrite the entire page if you use it after the page loads.
Jona
SearedIce
06-11-2003, 12:59 PM
i know but if you use it like this:
<html>
<body>
HAHA
<script language="javascript">
document.write("hehe");
</script>
HAHA
</body>
</html>
it won't mess up, and the page will look like this:
HAHAheheHAHA
oh...and it wouldn't work in my situation for whatever reason...i'll play around with it some more
SearedIce
06-11-2003, 01:03 PM
here's the entire thing i'm working on...i put *** before the line that i need help with
<script language="javascript">
function hadraw(){
var left = Math.floor(Math.random() * 800);
var top = Math.floor(Math.random() * 600);
element = document.createElement("div");
element.style.position="absolute";
element.style.top=top;
element.style.left=left;
element.style.width="20px";
element.style.height="20px";
element.style.color="white";
***element.innerHTML="<b>HA</b><scri" + "pt language='javascript'>alert('haha');</sc" + "ript>";
document.body.appendChild(element);
setTimeout("hadraw()",5000);
}
hadraw();
</script>
Why not just replace that line with alert('haha'); ?
Jona
SearedIce
06-11-2003, 01:12 PM
ok...lol....i'll explain what i want entirely:
i want the HA to pop up...i already got that part though...see the <b>HA</b>...and it works
i also want each "HA" to dissapear after a few seconds
what i think i can do it put a script in the <div> that contains the "HA" and make it set style.visiblity="hidden"; by using a timeOut();
if there's some other way for me to put this all together then please help
~John
You can make it alternate:
<script type="text/javascript">
function hadraw(){
var txtVar = "<b>ha</b>";
var left = Math.floor(Math.random() * 800);
var top = Math.floor(Math.random() * 600);
element = document.createElement("div");
element.style.position="absolute";
element.style.top=top;
element.style.left=left;
element.style.width="20px";
element.style.height="20px";
element.style.color="white";
if(element.innerHTML==txtVar){element.innerHTML="";}else{
element.innerHTML=txtVar;}
document.body.appendChild(element);
setTimeout("hadraw()",5000);
}
hadraw();
//Untested code
</script>
Jona
SearedIce
06-11-2003, 01:35 PM
nope, that won't do anything becuase each time the function is run a new LOCAL "element" is created and there is no way to communicate with the previous one...that's why i wanted "the previous one" to simply remove itself
oh...i know...i can make an array of a bunch of "elements"
but of course then my "ha"s will have to stop appearing at some point...
You can get the previous element with this:
element.previousSibling()
/*If the above doesn't work, try taking off the parenthesis.*/
Jona
SearedIce
06-11-2003, 02:09 PM
oh...i'm just reading that post of yours now...
i figured it out anyway though
this script will create any number of "ha"s and then count through them again, picking a new location for it...simply change the definition of the variable numberofhas:
<script language="javascript">
var numberofhas = 2;
someelements = new Array(numberofhas);
var counter = -1;
var counter2 = 0;
function hadraw()
{
counter = counter + 1;
counter2 = counter2 + 1;
if (counter == numberofhas)
{
counter = 0
}
var left = Math.floor(Math.random() * 800);
var top = Math.floor(Math.random() * 600);
if (counter2 < (numberofhas+1))
{
someelements[counter] = document.createElement("div")
someelements[counter].style.position = "absolute"
someelements[counter].style.width = "20px"
someelements[counter].style.height = "20px"
someelements[counter].style.color = "white"
someelements[counter].innerHTML = "<b>HA</b>"
document.body.appendChild(someelements[counter])
}
someelements[counter].style.top = top;
someelements[counter].style.left = left;
setTimeout("hadraw()",1000);
}
hadraw();
</script>
~John
See the result at http://www14.brinkster.com/drakej
there's 50 on that site :) enough to show the effect but now clutter my site too much..
i'll be getting rid of it soon or moving it to another page lol...it is annoying!
Heh, pretty cool. :)
Jona