2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2020

03/03/2003: How to Redirect to New URL Using JavaScript?

How to Redirect to New URL Using JavaScript?

This example shows how to redirect a web browser to another page. The JavaScript performs a countdown of the number of seconds left before the redirection is performed.

<HTML>
<HEAD>
  <TITLE>"Some Page" has moved!</TITLE>
  <META HTTP-EQUIV=Refresh CONTENT=6;URL=http://www.codebits.com/>
  <SCRIPT LANGUAGE="Javascript">
    <!--
    function countdown() {
      if ( document.myform.count.value > 0 ) {
        document.myform.count.value = document.myform.count.value-1;
        setTimeout("countdown()", 1000);
      }
    }
    //-->
  </SCRIPT>
  </HEAD>
  <BODY><H1>"Some Page" has Moved!</H1>
  The new address is:
  <A HREF="http://www.codebits.com/" TARGET=_top>http://www.codebits.com</A>.
  <P><FORM NAME=myform>
  You will be redirected to the above page in
  <INPUT NAME="count" SIZE="1" value="6"> secs.....)</FORM>
  <SCRIPT LANGUAGE="Javascript">
    <!--
    countdown();
    //-->
  </SCRIPT>
  </BODY>
</HTML>

03/02/2003: How Do I Load An Image and Determine Height and Width Using Java?

When loading an image over the net you frequently have to allow for long load times. The MediaTracker class is used to monitor a resource so that other things can happen (ie. threads) while the image is loading.

However, sometimes you really need for the image to totally load because you need the height and width measurements before continuing. The following code fragment show how to wait for an image to finish loading. - from Bob Withers in comp.lang.java.api.

// url is a String containing the URL of the image to load.
MediaTracker tr;
Image        im = toolkit.getImage(url);

tr.addImage(im, 0);
tr.waitForID(0);

// at this point the image is finished
// loading and the height and width can
// be determined.
int w = im.getWidth(this);
int h = im.getHeight(this);