Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old September 13th, 2006, 05:28 AM
Registered User
 
Join Date: Sep 2006
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Javascript Window Closer

Hi,

I have a javascript that rotates several banner images on my webpage and each image click through to a different webpage. The script is shown below:

<script language="JavaScript" type="text/JavaScript">
<!--
var urlArray = new Array(5);
var banArray = new Array(5);
var counter = 1;
var url = "webpage0.htm"; //initial URL

//add your necessary URL's
urlArray[0] = "webpage0.htm";
urlArray[1] = "webpage1.htm";
urlArray[2] = "webpage2.htm";
urlArray[3] = "webpage3.htm";
urlArray[4] = "webpage4.htm";

if(document.images)
{
  for(i = 0; i < 5; i++)
  {
    banArray[i] = new Image(183, 92);
    banArray[i].src = "banners/" + (i+1) + ".gif";
  }
}


function changeBanner()
{
  if(counter > 4)
   counter = 0;

  document.banner.src = banArray[counter].src;

  url = urlArray[counter];
  counter++;
}

var timer = window.setInterval("changeBanner()", 5000);

//-->
</script>


When one of the images is clicked, the new page opens in a new window. If this new window is then minimised and a different image banner from the original page is clicked, it opens the next new page in the minimised window. I would like the minimised window with the new page in it to maximise (or appear on top as the main window) when a new image is clicked!? Any help would be much apreciated!

regards

Peter
  #2 (permalink)  
Old September 13th, 2006, 08:11 AM
Friend of Wrox
 
Join Date: May 2004
Location: , , .
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Peter,

Try this:

function changeBanner()
{
  if(counter > 4)
   counter = 0;

  document.banner.src = banArray[counter].src;

  url = urlArray[counter];
  if(window.focus)
  {
  url.focus()
  }
  counter++;
}

This should ensure the new window is on top every time your counter goes round.

HTH
Joe


'sync' <cr>
The name specified is not recognized as an internal or external command, operable program or batch file.
  #3 (permalink)  
Old September 18th, 2006, 06:58 AM
Registered User
 
Join Date: Sep 2006
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your response, but this stops the image banners from rotating on the initial page.
  #4 (permalink)  
Old September 19th, 2006, 07:15 AM
Friend of Wrox
 
Join Date: May 2004
Location: , , .
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry Peter, I left out the last line of your code.

function changeBanner()
{
if(counter > 4)
counter = 0;

document.banner.src = banArray[counter].src;

url = urlArray[counter];

        if(window.focus)
        {
        url.focus()
        }

counter++;
}

var timer = window.setInterval("changeBanner()", 5000);

</script>



Cheers
Joe

'sync' <cr>
The name specified is not recognized as an internal or external command, operable program or batch file.


Similar Threads
Thread Thread Starter Forum Replies Last Post
A significant step closer to making TBH modular jimibt BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 October 12th, 2007 04:31 AM
New window not being open by javascript akhilesh_g Classic ASP Professional 1 September 14th, 2007 04:13 AM
Popup window from javascript arnabghosh Javascript How-To 1 March 2nd, 2006 10:17 AM
Popup window from Javascript arnabghosh Javascript 3 March 1st, 2006 01:09 AM
New Window in PHP JavaScript ajutla PHP How-To 2 August 21st, 2004 05:33 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.