Jump to content

is there a code to open a new window and close the old in one click?


radiohomer

Recommended Posts

ok so its as the title says

is there a way to open a new window and close the old one?

 

ok so ill explain a little more on what i want to achieve

 

i have 2 pages

  index.php

  page1.php

 

on the index.php page i have a dropdown box with 3 options

 

<select>
<option>--Choose--</option>
<option onclick="window.open('index.php')">Index</option>
<option onclick="window.open('page1.php')">Page 1</option>
</select>

 

ok so the dropdown box is doing what i would like by opening a new window but i would like to close the old one.

 

at the moment this is whats happening

the user is viewing "index.php" he clicks on the dropdown and selects "Page 1" this opens a new window displaying the content of page1.php but the index.php page is still open.

 

this is what i would like to happen

the user is viewing "index.php" he clicks on the dropdown and selects "Page 1" this opens a new window displaying the content of page1.php and also closes index.php.

 

is this possible??

i just cant get it to work... i have seen it done before but cant find the website that i saw it on

 

i have tried using onclick, onchange ect ect

if anyone could help me with this that would be great

Link to comment
Share on other sites

could try something like

<option onclick="window.open('page1.php'); window.close('index.php')">Page 1</option>

thanks for your input Fugix

i have just tried that and it didnt work

i have found a different way to do this

 

my whole reason for the code above was because index.php has 3 frames on there and whenever i clicked a link it just opened in that frame and left the rest showing the content from index.php

i never thought to use parent.top or target="_top"

 

here is the code i have used and have got working

 

<select>
<option>--Choose--</option>
<option onclick=parent.top.location="index.php">Index</option>
<option onclick=parent.top.location="page1.php">Page 1</option>
</select>

 

this gets rid of the frames on the index page and loads page1.php in the full view

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.