0

I might have a strange request. I am not that good as a scripter so the method I used might be strange but a script I made does this: You select an option and this option has a value which is a link. When submitting the form I want the link (=value) to be opened in a new tab. This I achieved but the method I used makes popup blockers block the new window. Do any of you have a idea howto bypass this?

    <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="get" class="formLayout">
 <!-- Dropdownlinks-->
    <select name="bestemming" size="1" onchange="document.getElementById('text_content').value=this.options[this.selectedIndex].text"> 
      <option value="http://youtube.be">Test1 (YT)</option>  
      <option value="http://google.be">Test2 (GooGle)</option>  
      <option value="http://bing.be">Test3 (Bing)</option>    
    </select
<!-- Terms -->
<br /><input type="checkbox" name="Terms" value="Download">
 I agree with terms
<br />
    <input type="submit" value="Verzenden" onclick="if(!this.form.Terms.checked){alert('Je moet akkoord gaan met de downloadvoorwaarden!');return false}" /></p>
</form>
<?
    $link = ($_GET['bestemming']);
    echo '<script language="javascript">window.open("' . $link . '" ,"_blank");</script>';
    ?>

Do you have any suggestions?

Thank you very much in advance!

  • 1
    Why are you not opening the link using `header()` in PHP? May be this link will help you out [http://stackoverflow.com/questions/9514698/bypass-popup-blocker-on-window-open-when-jquery-event-preventdefault-is-set](http://stackoverflow.com/questions/9514698/bypass-popup-blocker-on-window-open-when-jquery-event-preventdefault-is-set) – Vikas Arora Jul 20 '14 at 13:39
  • You should be able to set `target="_blank"` and set the action of the form to the desired url on submit. – Popnoodles Jul 20 '14 at 15:51
  • header() doesnt open in a new tab which I want (as I want to keep users on my own site). – Pieter Populaire Jul 20 '14 at 18:05
  • Setting the form action cant work because the chosen option in the dropdown menu will determine which link will be opened. – Pieter Populaire Jul 20 '14 at 18:06

1 Answers1

0

@Popnoodles, your answer gave me an idea. How I fixed it:

  <form action="#" target="_blank" method="get" class="formLayout">

Same form

and then

<?
    $link = ($_GET['bestemming']);
    header("Location: $link");
    ?>