[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 451
  • Last Modified:

javascript popup problem

My javascript is not great.

I use this to open a window

function popup(url, dimensions)
{
      newwindow=window.open(url,'name', dimensions);
      if (window.focus) {newwindow.focus()}
}

with the links

<a href="javascript:popup('delivery&returns.php', 'height=450,width=270');">delivery&returns </a> |

<a href="javascript:popup('contact.php', 'height=300,width=350');">contact</a>


The problem is if I click on one then another the new page is put in the 'old' window wich is the wrong dimensions. any ideas?

Ross
0
roscoeh23
Asked:
roscoeh23
  • 2
1 Solution
 
TimCotteeCommented:
Hi roscoeh23,

You have to change the 'name' for each popup, otherwise the same named window will be reused.

function popup(url, dimensions,what)
{
     newwindow=window.open(url,what, dimensions);
     if (window.focus) {newwindow.focus()}
}

with the links

<a href="javascript:popup('delivery&returns.php', 'height=450,width=270','big');">delivery&returns </a> |

<a href="javascript:popup('contact.php', 'height=300,width=350','small');">contact</a>


Tim Cottee
0
 
dnlakhaniCommented:
<script>
function popup(url, dimensions,name)
{
     newwindow=window.open(url,dimensions,name);
     if (window.focus) {newwindow.focus()}
}
</script>

change the name for different window

<a href="javascript:popup('delivery&returns.php', 'height=450,width=270','test');">delivery&returns </a> |

<a href="javascript:popup('contact.php', 'height=300,width=350','test11');">contact</a>
0
 
Tahir_ImranCommented:
THis will always work for you :
function popup(url, dimensions,what)
{
    day = new Date();
    id = day.getTime();
  newwindow=window.open(url,id, dimensions);
}

with the links

<a href="javascript:popup('delivery&returns.php', 'height=450,width=270','big');">delivery&returns </a> |

<a href="javascript:popup('contact.php', 'height=300,width=350','small');">contact</a>
0
 
Tahir_ImranCommented:
a Sight modification , No need to pass what
THis will always work for you :
function popup(url, dimensions)
{
    day = new Date();
    id = day.getTime();
  newwindow=window.open(url,id, dimensions);
}

with the links

<a href="javascript:popup('delivery&returns.php', 'height=450,width=270');">delivery&returns </a> |

<a href="javascript:popup('contact.php', 'height=300,width=350');">contact</a>
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now