Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 234

# javascript: open 2 windows and slide them over the screen to a meeting point

Hi, got a JS-problem:

I want open 2 small windows on different positions of the screen. Then they should move/slide over the screen to meet each other in a point.
This script should also work with different  screen resolutions. I need it urgent.

0
• 3
1 Solution

Commented:
try this script:

<script language='javascript'>
<!--
//Set location of two windows
win1loc = 'page1.html'
win2loc = 'page2.html'

//Set x and y coordinates of first window
Xwin1 = 100
Ywin1 = 100

//Set x and y coordinates of second window
Xwin2 = 800
Ywin2 = 100

//Set height and width of first window
widthwin1 = 300
heightwin1 = 300

//Set height and width of second window
widthwin2 = 300
widthwin2 = 300

//Set speed for the two to move together(milliseconds) and pixels moved per amount of time
speed = 20
pixelsper = 1

function openwins()  {
win1 = window.open(win1loc,'win1','height = ' + heightwin1 + ',width = ' + widthwin1 + 'left = ' + Xwin1 + ', top = ' + Ywin1)
win2 = window.open(win2loc,'win2','height = ' + heightwin2 + ',width = ' + widthwin2 + 'left = ' + Xwin2 + ', top = ' + Ywin2)
movewins()  {
}
spacebetween = (Xwin1 + heightwin1) - Xwin2
function movewins()  {
if(spacebetween > 0)  {
win1.moveBy(pixelsper,0)
win2.moveBy(-pixelsper,0)
spacebetween -= pixelsper
setTimeout('movewins()',speed)
}
}
0

Commented:
ok,  a few corrections to make.  Here's what the code needs to be:

<script language='javascript'>
<!--
//Set location of two windows
win1loc = 'test.html'
win2loc = 'testit2.html'

//Set x and y coordinates of first window
Xwin1 = 100
Ywin1 = 100

//Set x and y coordinates of second window
Xwin2 = 800
Ywin2 = 100

//Set height and width of first window
widthwin1 = 300
heightwin1 = 300

//Set height and width of second window
widthwin2 = 300
heightwin2 = 300

//Set speed for the two to move together(milliseconds) and pixels moved per amount of time
speed = 20
pixelsper = 1

spacebetween = (Xwin2 - Xwin1 - widthwin1)/2
function openwins()  {
win1 = window.open(win1loc,'win1','height = ' + heightwin1 + ',width = ' + widthwin1 + ',left = ' + Xwin1 + ', top = ' + Ywin1)
win2 = window.open(win2loc,'win2','height = ' + heightwin2 + ',width = ' + widthwin2 + ',left = ' + Xwin2 + ', top = ' + Ywin2)
movewins()
}
function movewins()  {
if(spacebetween > 0)  {
win1.moveBy(pixelsper,0)
win2.moveBy(-pixelsper,0)
spacebetween -= pixelsper
setTimeout('movewins()',speed)
}
}
//-->
</script>

This works fine on my computer(I have IE6), hope it works for you.

{Slam}
0

Commented:
Oh, just a note. The only way this will work is if the two windows you are opening are windows on your site.  I tried using it with opening google and yahoo, and it gave me an error message

{Slam}
0

Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: superslamwich {http:#8242000}