Originally posted by Sri Ram:
for(i=1;i<=3000000;i++){}
As you've observed, looping to create a delay as not a good idea, as faster machines will execute the loop faster.
You may want to look at javascript documentation for the setTimeout method, e.g.: