A preserved archive of the Logical Gamers community forums, 2009-2025. The original threads and posts, served read-only. Registration, posting and private messages are gone for good.

Proper JavaScript Window Management?

972 views · started by Kingz V ·
#1
Proper JavaScript Window Management?
Let's say you have a script.

for example

// ==/UserScript==
clix();
function clix() {
//generate random number
x = getRandomInt(1, 20)
y = getRandomInt(1, 28);
clixdo(x, y);
}
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}


Where clixdo is javascript for window.open( url + x + y )

How would you go about managing the windows, and properly closing them?

What about with a given time interval. (page needs to load another page and wait x time)

Given the code could be changed to new_window = window.open( some url ) and could be added to an array.
#2
I'm not exactly sure what you're trying to do, but if you're trying to send web requests you could just use XML.


function httpGet(theUrl)
{
var xmlHttp = null;

xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", theUrl, false );
xmlHttp.send( null );
return xmlHttp.responseText;
}


Not the best with JS so couldn't help you with waiting functions, everytime i tried writing one it just froze my browser :x
#3
Thanks :3

I did learn something from your snippet there.

I'm not sure if it'll work through web-requests though, but it's worth a shot.

page has to load another and do an ad-timeout to be valid.
#4
I am pretty sure, but I may be wrong, that when you open a window, it returns a window object.

var myNewWindow = window.open("whatever")

To manage that window, you would use myNewWindow. You can store it in whatever variable or array of variables that you want.



I believe there are also window names that work something like:
window.open("url", "myWindowName")

such that you can reference:
window.myWindowName.close(), etc.



That markup may be incorrect, as I don't ever use windows ever. Popup blockers kinda killed the window.open() usefulness, and I don't oppose that.
#5
GAMEchief wrote:
I am pretty sure, but I may be wrong, that when you open a window, it returns a window object.

var myNewWindow = window.open("whatever")

To manage that window, you would use myNewWindow. You can store it in whatever variable or array of variables that you want.



I believe there are also window names that work something like:
window.open("url", "myWindowName")

such that you can reference:
window.myWindowName.close(), etc.



That markup may be incorrect, as I don't ever use windows ever. Popup blockers kinda killed the window.open() usefulness, and I don't oppose that.


This would be correct.

But, I'm more curious about the implications of running multiple windows. That's the real problem.
#6
Where's the problem? You can have multiple windows. It just takes multiple variables or window names.

myWindows[myWindows.length] = window.open("etc")