0

Here is my code, I want add.php to open in the current tab not open a new window all together.

<input type="submit" class="btn" value="Add Record" onclick="addrecord()">
          <script>
               function addrecord() {
                    window.open("add.php", "Add Record", "_self");
               }
          </script>

4
  • 1
    due to window.open .always it will open in new window..u jst use window.location='someUrl.com'; or location.href='http//eg.com'; Commented Jan 7, 2016 at 7:14
  • if you want to open form then try calling AJAX and replace HTML of current window. Commented Jan 7, 2016 at 7:16
  • Redirect the page. check my answer. Commented Jan 7, 2016 at 7:19
  • @Tye Lucas, Accept answer if that solved your problem Commented Jan 7, 2016 at 7:57

1 Answer 1

1

For your case, you should redirect the page not opening a new window. Try below snippet.

<input type="submit" class="btn" value="Add Record" onclick="addrecord()">

    <script type="text/javascript">
                   function addrecord() {
                        window.location = "http://www.google.com";
                   }
    </script>
Sign up to request clarification or add additional context in comments.

6 Comments

sadly the above code does nothing =/
Try this onclick="window.location = "google.com";"> if it works then put the snippet in the head tag
I solved my own problem last night after going to bed, it hit me like a train, and it works brilliantly! <?php if(isset($_POST['addentry'])) { header('Location: ./add.php'); } ?>
glad to hear. let me know if you need any thing to accept the answer
<div class="addentrydiv"> <input type="submit" class="btn" name='addentry' value="Add Record"> </div>
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.