Help me with this javascript please.

Talk about just about anything else that is non-gaming here, but keep it clean
Post Reply
User avatar
BigTinz
128-bit
Posts: 972
Joined: Tue Jun 03, 2008 12:32 pm
Location: Alabama

Help me with this javascript please.

Post by BigTinz »

I have to turn in something clever in javascript for my class. I decided to re-create an old prank.

A window pops up and says "You've won a free cupholder would you like to accept?"

You click yes and your cd drive opens.


I've managed to get the operation to work in Internet Explorer(which is what we have to do) but I have one problem.

Since I've assigned the the alert.window to open the cd tray...I don't know how to customize the text.

Instead of it saying [object] I want it to say something else. Can anyone help me?

Here is this code, just copy it to a .txt and make it an html(only works with IE)

Code: Select all

<html> 
<head> 
<title>Free Cup Holder</title> 
<script language="JavaScript" type="text/javascript"> 
<!-- 
function EjectAll(){ // Eject all CD-ROM drives 
var col=Player.cdromCollection, c=0; 
alert(col) 
while(c<col.count)col.item(c++).eject(); 
} 
//--> 
</script> 
</head> 
<body onload="EjectAll()"> 
<OBJECT ID="Player" 
CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" 
style="display:none" width="245" height="240"> 
</OBJECT> 
</body> 
</html> 
User avatar
lordofduct
Next-Gen
Posts: 2907
Joined: Sat Apr 01, 2006 12:57 pm
Location: West Palm Beach

Re: Help me with this javascript please.

Post by lordofduct »

a) the alert(...) method contains an arg to pass as a param for the message to display. You are passing an enumerable Array as the arg, which when coerced to String returns [Object] or [Array] depending.

so just pass in the value:

function EjectAll(){ // Eject all CD-ROM drives
var col=Player.cdromCollection, c=0;
alert("You've won a free cupholder would you like to accept?");
while(c<col.count)col.item(c++).eject();
}



b) this only works on very few computers. It's an old trick that has been blocked for most. Even though it still works on your IE it is probably because of your version or something. This doesn't mean it's going to work on all IE instances... such as when you get to school.

c) This thing is DATED. No offense, it's just hardly creative, and is literally a cut and paste from the interwebs. I can google and find your code verbatim. And so can your teacher. And if your teacher knows anything (which I hope he does, because I'm a novice I saw it), he's going to know this is plagurism.


I mean come on, this is a classic I wrote in 30 seconds and it I actually wrote it instead of copy-pasta

Code: Select all

<html>
<head>
<title>Annoying Bastard aren't I?</title>
<script language="JavaScript" type="text/javascript">
function beginAnnoy()
{
	var rnd = Math.round( Math.random() * 10 ) + 10;
	
	alert( "Click to Continue" );

	var arr = [ "Just once more", "You're almost there", "come on you can do it", "Are you having problems?", "wow what is wrong with you", "you might want to clear your cache or something" ];
	
	while (rnd--)
	{
		var val = arr[ Math.floor( Math.random() * arr.length ) ];
		alert( val );
	}
	
	alert( "you finally made it!" );
}
</script>
</head>
<body onload="beginAnnoy()">
<OBJECT ID="Player"
CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"
style="display:none" width="245" height="240">
</OBJECT>
</body>
</html> 
www.lordofduct.com - check out my blog

Space Puppy Studios - games for gamers by gamers
User avatar
BigTinz
128-bit
Posts: 972
Joined: Tue Jun 03, 2008 12:32 pm
Location: Alabama

Re: Help me with this javascript please.

Post by BigTinz »

I got assisted and owned in the same post.

See, I've tried what you said(replacing it) but when I do that...it doesn't work. The alert(col) is the trigger for the tray to open.
Post Reply