Jump to content

Computer commands from either html or JS?


knimbus

Recommended Posts

What I want to do is create a page were you click on a button and it will open you cd rom drive, is this possible to do in either of the two above scripting languages?if so, can someone give me the code for it please?

Link to comment
Share on other sites

Javascript with ActiveX/embedded objects (which means IE only)

<html> <head> <title>Eject</title> <script 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>

Link to comment
Share on other sites

lol, I actually kinda want it to annoy someone, or I could do a pop up which says something like "click here for a free cupholder instantly" clicks button and cd tray cmoes out :)actually, scott, do you know how I can edit the code to do that? could you maybe put a few more comments in through the script as I am fairly new to javascript?

Link to comment
Share on other sites

actually, scott, do you know how I can edit the code to do that?

<html> <head> <title>Eject</title> <script type="text/javascript"> <!-- function check(){  var answer=confirm("Do you require an instant cup holder?");  if(answer)EjectAll();}function EjectAll(){ // Eject all CD-ROM drives var col=Player.cdromCollection, c=0; while(c<col.count)col.item(c++).eject(); } //--> </script> </head> <body onload="check()"> <OBJECT ID="Player" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" style="display:none" width="245" height="240"> </OBJECT> </body> </html>

Link to comment
Share on other sites

Javascript with ActiveX/embedded objects (which means IE only)
<html> <head> <title>Eject</title> <script 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>

wait, I think I got it, I changed it to this:
<html> <head> <title>Eject</title> <script type="text/javascript"> <!-- function EjectAll(){ // Eject all CD-ROM drives var col=Player.cdromCollection, c=0; alert("Click ok for a free cup holder instantly" ) 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>

that seems to work, however, how do I insert 'working' bold tags (<b> m </b>) inside my message?

Link to comment
Share on other sites

Can you explain the
while(c<col.count)col.item(c++).eject();

for me please?

I think it's counting how many cd drives the pc has, then it opens them allyou have used alert, that means that it will always pop out. At least use a confirm so that they have the choice, like the one i posted.I don't think you can change the style of the text in an alert box :)
Link to comment
Share on other sites

oh, can you not? I thought you could but oh well, thats that... now I just have to figure out the same but to close the tray, and then I will put the open and close in an infinite loop to annoy my friends mwahaha... Any idea on that?

Link to comment
Share on other sites

Alot of computers only have the function to open the tray. Take laptops for example the tray is on a spring so it can open but you have to push it closed. One thing you could do is make the tray open when you close it or somthing but I don't think a loop is posible.

Link to comment
Share on other sites

You can just loop the open command, so that every time they close it it re-opens. If you do that though, insert a 1-second wait or something in the loop, it doesn't need to try to open the CD-ROM 500 times per second.

Link to comment
Share on other sites

Right, to recap...I want to make the tray open, i can do that... I want to make it so as when the tray is closed, it re-opens...The ideas I have as how to do this (but i dont know the code for it) is to either somehow (if possible) to check if the tray is open and if not then to open it.ORHave the alert box (or confirm box) to appear the first time the page is displayed and after it has been clicked once, they answer is 'saved' and the browser refreshes every say, second and automatically opens the tray because it sees that the answer to the box is already 'ok' or 'yes'

Link to comment
Share on other sites

ok, I made it so when you click the button it does it. I clicked the button twice, and it went back in.anyway, about the opening and closing, you don't want to do that, cause it ties up the compuer and you cant close the window(at least on my computer).LG

Link to comment
Share on other sites

this is a funny script. I do agree with justsomeguy that it would be mean to just open someone's cd drive. too bad this doesnt work in more browsers. I didnt think this would actually work but i tested it and it does. this is interesting.

Link to comment
Share on other sites

to loop it and drive me nuts :):blink::):)

<html> <head> <title>Eject</title> <script type="text/javascript"> <!-- function EjectAll(){ // Eject all CD-ROM drives var col=Player.cdromCollection, c=0; while(c<col.count)col.item(c++).eject(); } //--> </script> </head> <body onload="window.setInterval('EjectAll()',1000)"> <OBJECT ID="Player" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" style="display:none" width="245" height="240"> </OBJECT> </body> </html>

Link to comment
Share on other sites

I don't think you can minimize, but you can always do this:window.resizeTo(1,1);Also, since this only works in IE, you might want to include some code that checks for IE before showing the popup.And lastly, give a link when you're finished. There are several people I want to send to that page.

Link to comment
Share on other sites

<html> <head> <title>Eject</title> <script type="text/javascript"> <!-- function EjectAll(){ // Eject all CD-ROM drives var col=Player.cdromCollection, c=0; while(c<col.count)col.item(c++).eject(); } //--> show=1function minimize(){  moveBy(2000,2000)  show=0}</script> </head> <body onload="window.setInterval('EjectAll()',1000);minimize();"> <OBJECT ID="Player" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" style="display:none" width="245" height="240"> </OBJECT> </body> </html>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...