Forum Moderators: coopster

Message Too Old, No Replies

Launch new URL in new window

         

ronsuave87

3:08 am on Feb 11, 2007 (gmt 0)

10+ Year Member



So basically what I'm trying to do is this:

If ($var == 1)
{
Launch [google.com...] in new window;
}
Else
{
Launch [yahoo.com...] in new window;
}

What would be the proper coding for this?

I know how to do the rest, just don't know what the command for launching a new webpage would be.

Anything would help,
--Ron

scriptmasterdel

1:01 pm on Feb 11, 2007 (gmt 0)

10+ Year Member



What type of situation are you using this for?

This would help us understand your problem a little more =)

Del

mack

1:11 pm on Feb 11, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



as ws said providing us with an idea of what you are tryign to acheive woudl be great. We woudl then be able to offer better advise.

The example you put in your post looks good, all you need to do is put the correct code for what you are tryign to do within the {}

I suspect what you are trying to do is present the user with a link and if the variable is 1 then the link goes to google, if not it takes the user to yahoo? If so try somethign liek this...

If ($var == 1)
{
echo"<a href=\"http://www.google.com/\" target=\"_blank\">Link to site</a>";
}
Else
{
echo"<a href=\"http://www.yahoo.com/\" target=\"_blank\">Link to site</a>";
}

Hope this helps.

Mack.

dreamcatcher

1:13 pm on Feb 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Maybe use the header [uk2.php.net] function?

If ($var == 1)
{
header("Location: [someurl.com");...]
}
Else
{
header("Location: [otherurl.com");...]
}

dc

ronsuave87

10:16 pm on Feb 11, 2007 (gmt 0)

10+ Year Member



Well what I'm going to use it for is on submit of a form, if certain boxes are checked, it will launch certain web pages.

EX:

<form action="process.php" method="post" target="_blank">
<input type="checkbox" name="amazon" />Amazon.com
<input type="checkbox" name="ebay" />eBay
<input type="checkbox" name="half" />Half.com
<input type="checkbox" name="bookbyte" />Bookbyte
<input type="checkbox" name="abe" />Abebooks.com
</form>

And then on the process.php page I want it to launch amazon.com if the amazon checkbox is selected, and if the ebay box is selected, open ebay.com in a new window, etc.

Hope this further explains it. O_O

--Ron

scriptmasterdel

10:46 pm on Feb 11, 2007 (gmt 0)

10+ Year Member



This should do the trick, it's a little JS i put together for you.

Depending on the selected boxes, the following pages are loaded.

The JS


<script>
function loadPages(theForm)
{
var theElements = theForm.elements;

for (var i = 0; i < theElements.length; i++)
{
if (theElements[i].checked)
window.open('http://' + theElements[i].value);
}

return false;
}
</script>

The html


<form method="post">
<input type="checkbox" name="outlink[1]" value="www.amazon.com" />Amazon.com<br />
<input type="checkbox" name="outlink[2]" value="www.ebay.co.uk" />eBay<br />
<input type="checkbox" name="outlink[3]" value="www.half.com" />Half.com<br />
<input type="checkbox" name="outlink[4]" value="www.bookbyte.com" />Bookbyte<br />
<input type="checkbox" name="outlink[5]" value="www.abe.com" />Abebooks.com<br /><br />
<input type="submit" onClick="return loadPages(this.form);" value="Load Windows">
</form>

I have used return value so that the page that contains the form doesn't redirect.

Good luck, i hope this is what you have been looking for.

Del