Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Get popups to open with target

    Hi!

    I know how to make a new window appear by using...

    Code:
    <script language="javascript">function newwin() { window.open("http://www.foo.com","newwin","width=250,height=300") } </script>
    <a href="javascript:newwin()">New Window</a>
    But in this specific instance, I want to do it using:

    Code:
    <a href="http://www.foo.com" target="newwin">
    I remember reading that this was possible but I can't work out the script which goes in the HEAD for it!

    Thanks so much for anyone who can help

    Chris

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Something like this?
    Code:
    <html>
    <head>
    <script type="text/javascript">
    function newwin(url)
    {
    	var thewin = window.open(url,'thewin','width=250,height=300')
    	if(thewin) thewin.focus();
    }
    function setWin()
    {
    	var thelinks = document.getElementsByTagName('a');
    	for(var i = 0; i < thelinks.length; i++)
    	{
    		if(thelinks[i].getAttribute('target') == 'newwin')
    		{
    			thelinks[i].onclick = function()
    			{
    				newwin(this.href);
    				return false;
    			}
    		}
    	}
    }
    window.onload = setWin;
    </script>
    </head>
    <body>
    <a href="http://www.google.com" target="newwin">google</a><br>
    <a href="http://www.yahoo.com" target="newwin">yahoo</a><br>
    <a href="http://www.codingforums.com">codingforums</a>
    </body>
    </html>
    Last edited by _Aerospace_Eng_; 06-24-2006 at 05:40 PM.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks!

    You're a genius... thanks so much!!

    Chris


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •