Open two links with one click

Discussion in 'Web Design and Development' started by carlosbutler, Sep 18, 2008.

  1. carlosbutler macrumors 6502a


    Feb 24, 2008
    London City
    I am trying to create somthing which will allow me to click on one link, but it opens up to different pages. now in html i believe you can not have two href's in the same <a> tag. but is there a JS way of doing this. if not, how do you do it in flash, since the only way i can think of is using an invisible layer, but thats just one layer

  2. SrWebDeveloper macrumors 68000


    Dec 7, 2007
    Alexandria, VA, USA
    Javascript method:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
    <html xmlns="">
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Open Two Windows</title>
    <script language="javascript">
    function OpenTwoLinks() {
        var WinReference1 = ("","link1");
        var WinReference2 = ("","link2");
    return false;
    <a href="#" onClick="return OpenTwoLinks()">Open Two Links here (Disable Pop-Up Blocker for this domain)</a>

    This is a simplified example for demo purposes, tested and works. I used an onClick event in a standard link which calls a JavaScript function that uses to open two windows. I included a reference to each window so you can in your own code communicate with the window as desired. Up to you to customize each window and use your own links. I kept it simple, in the real world I'd probably set the links in two global variables at the top of the JavaScript or whatever and pass them as arguments to the function.

    Don't forget that users can disable JS and also set pop-up blockers so this method isn't foolproof.

    On a side note, this is EXTREMELY irritating to users to even do this, so I will make an assumption you're not a porn entrepreneur and have a sound business or personal need. At least warn users to disable popups and describe the originating link to let them know two windows will open. If you ask for advice how to automate this, I might not reply because I don't give advice to kiddie scripters seeking to blast windows to unsuspecting users.

    But you get the idea, regardless of intent. I had to give the speech, it's an ethical imperative.

  3. angelwatt Moderator emeritus


    Aug 16, 2005
    I'll echo SrWebDeveloper's sentiment that most visitors will hate having two links open, so be careful how you use this or you'll be losing visitors.
  4. spaghettishark macrumors newbie

    Oct 2, 2008
    Just found this thread while searching how to do something similar for an art project I'm doing.

    I've gotten the suggested code to work, but what I'm wondering is there a way to designate the size of the windows you want to pop up? I had this working when I only had one window popping, but it won't work for the two.

    Here's what I'm using:
    href="#" onClick="return OpenTwoLinks(this.href, 'popupwindow', 'width=500,height=500'); return false;">

    Ahh, nevermind, I've got it figured out. Needed to set the size parameters in the heading part.

Share This Page