HTML Make browser window move randomly

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Guest
Hi, I can do basic programming in HTML, but there's something I need help with. I need some code to make the browser window to 'restore down' and move into random places very quickly. It is for a game I am making to kill some time. The gif will play and the browser will move too quickly for you to close it. Does anybody know how to do this?

Thanks
 
For security reasons, I doubt that any browser would allow itself to be moved by a page it has visited. And even if it was allowed, I guess JavaScript is to be responsible for such browser-related things and not HTML (A markup language).
 


Thanks for the reply. Yes from what I'v read, Java takes care of the movement of images and other things. There is a website called [redacted](NOT NICE AT ALL) That does this. I just need some similar code to make the game.

 


What that website does (Just visited it -.-) is that, it opens links in new windows (The open Window takes a random position):

So you should make an infinity loop in JavaScript (JavaScript IS NOT Java!! Its too much different and have nothing to do with each other.):

JavaScript:
<script>
while(1)
{
     var newWindow = window.open("URL","name of window","height=500px, width=500px");
}
</script>

DO NOT CREATE A WEBSITE SUCH AS THAT ONE!
 


Thanks again for the reply. when I replace "URL" with funny.gif, google chrome just opens a blank window that doesn't move. I have tried enabling all popups but it hasn't seemed to work. Do you know why it's not working?

 


Is the image file in the same folder/directory/path as the HTML source file?

And I have told you before... The window doesn't move and wont move, the trick was to create too many windows and they would automatically take random positions which will appear that they are moving.

Can you copy paste that snippet of your code please?
 



I haven;t got very far. This is what I've got:

<script>
while(1)
{
var newWindow = window.open(""funny.gif","name of window","height=100px, width=100px");
}
</script>
 
This must work:

JavaScript:
<script>
var newWindow;
while(1)
{
var random = (Math.random() * 300) + 1;
var specs = "height=100px, width=100px, left=" + random + ", top=" + random;
newWindow = window.open("URL","test", specs);
newWindow.close();
}
</script>

You might want to edit the code a bit to meet your need.
 
You can actually use window.moveTo(x, y) or window.moveBy(x,y). These functions date back to the days of Netscape Navigator. However, most (if not all) major modern browsers have restrictions on when and/or how these functions will work precisely because of what you're trying to do.
 


Thanks for that. It opens the windows how I want them but it just doesn't play the gif? I have tried replacing the URL with: C:\Users\Andrew\Desktop\Site LOL\funny.gif
but it just opens blank windows. Is there a solution?

 
That's because the window is closing too fast for you to see the image, you can do it better with setInterval rather than while. I have improved your code:

JavaScript:
<script>
	var newWindow;
	
	setInterval(function(){
        var RandomX = (Math.random() * 1024) + 1;
        var RandomY = (Math.random() * 768) + 1;
	var specs = "height=100px, width=100px, left=" + RandomX + ", top=" + RandomY;
	newWindow = window.open("url.gif","test", specs);
	}, 1000);
	
	setInterval(function(){
	newWindow.close();
	}, 2000);
	
</script>

You might need to change the timings (IN MILLISECONDS) to suit the GIF play duration.
 


Okay, Is there a solution to do that? I have Adobe Fireworks on my PC, do you think that will do it?
 


I just sent you the code... It should work now
 


Thank you so much! Just a bit more tweaking, is there any way they can keep popping up after the original page has been closed? (like on gloryholefoundation) and What numbers would I have to change to speed it up?

& thank you for your help so far I really appreciate it

 


Anytime :) Yes there is a way, which is to make every window create another window (With the same html file) and kill itself after creating the window, but you should load the image on the html page like this:

JavaScript:
<html>
<img src="url.gif"/>
<script>
	var newWindow;
	setInterval(function(){
        var RandomX = (Math.random() * 1024) + 1;
        var RandomY = (Math.random() * 768) + 1;
	var specs = "height=100px, width=100px, left=" + RandomX + ", top=" + RandomY;
	newWindow = window.open("test.html","test", specs);
	}, 1000);
	setInterval(function(){
		self.close();
	}, 2000);
</script>
</html>

However
, this wont work with most browser as it is considered a security flaw, so the window wont be able to close itself.

The numbers are in milliseconds, so 2000 means 2 seconds and 1000 means 1 second. If you want to speed it up, decrease those delay times, so the 2000 would become 1000 for example, and the 1000 becomes 500, but this wont let the user see the whole GIF animation since its too short.
 


so the speed is looking quite good. So there's definately no way to do it?
If not, then fair enough, is there a way to cover the close button on the chrome browser and the task bar?
 
Okay, I have had a look and it just seems impossible to do it. Would it be easier to get the code for GLF and just replace the horrific image and sound?