0

I have set up a textbox that passes a value to the url, but I can't get it to open in a new tab.

<html>
<script type="text/javascript">
function goToPage() {
        var page = document.getElementById('page').value;
        window.location = "http://" + page + ":443";
        window.target = "_blank";
        }
</script>
<table><tr><td><img src="DEA_75.jpg"></td>
<td>Service Tag<br>
<input type="text" id="page"  size="5"/><br>
<input type="submit" value="submit" onclick="goToPage();"/></td>
</html>

Thanks!

David Peck
  • 27
  • 1
  • 9

2 Answers2

2
<html>
<script type="text/javascript">
function goToPage() {
        var page = document.getElementById('page').value;
        window.open("http://" + page + ":443","_blank");
        }
</script>
<table><tr><td><img src="DEA_75.jpg"></td>
<td>Service Tag<br>
<input type="text" id="page"  size="5"/><br>
<input type="submit" value="submit" onclick="goToPage();"/></td>
</html>

This will do your task :)

Shubham Gupta
  • 414
  • 7
  • 19
1

window.location means that you want to load new URL into the CURRENT page. That's why it fails. You just need to open new window instead:

<html>
<script type="text/javascript">
function goToPage() {
        var page = document.getElementById('page').value;
        window.open("http://" + page + ":443");
        window.target = "_blank";
        }
</script>
<table><tr><td><img src="DEA_75.jpg"></td>
<td>Service Tag<br>
<input type="text" id="page"  size="5"/><br>
<input type="submit" value="submit" onclick="goToPage();"/></td>
</html>
Elvin Haci
  • 3,503
  • 1
  • 17
  • 22