Previous Example-|-Next Example-|-Return to Chapter Listing

Example 10.8:
window.location and document.location

Click on this button to create a new window (don't close that window):

Click on this button to view the value held by the document.location property (you'll get an error if you haven't clicked on the first button yet, or if you closed the window):

Click on this button to view the value held by the window.location property:

Change the window.location object's href property:

Try changing the document.location property (it won't work):


These are the scripts we used. First this bit in the HEAD... <SCRIPT LANGUAGE="JAVASCRIPT"> <!-- function WinOpen() { NewWindow = open("2-1.htm","Window1","toolbar=yes,height=250,width=450,"); } //--> </script> Then these buttons: <FORM> <I>Click on this button to create a new window:</I><BR> <input type="button" name="WindowButton" value="Create Secondary Window and place Example 2.1 in the window" onclick="WinOpen()"> <P> <I>Click on this button to view the value held by the </I>document.location<I> property:</I><BR> <input type="button" name="Button3" value="Show secondary document.location property" onclick="alert('document.location = ' + NewWindow.document.location)")"><P> Click on this button to view the value held by the </I>window.location<I> property:</I><BR> <input type="button" name="Button3" value="Show secondary window.location.href property" onclick="alert('window.location.href = ' + NewWindow.location.href)")"><P> <I>Change the </I>window.location<I> object's </I>href<I> property:</I><BR> <input type="button" name="Button2" value="Change the secondary window.location object to example 2-2" onclick="NewWindow.location.href = '2-2.htm'")><P> <I>Try changing the </I>document.location<I> property (it won't work):</I><BR> <input type="button" name="Button2" value="Change the secondary window's document.location object to example 2-3" onclick="NewWindow.document.location = '2-3.htm'") </form>
Previous Example-|-Next Example-|-Return to Chapter Listing