0

I have a folder that contains two aspx empty website files (task1.aspx , task2.aspx). That's the code that I have in task1.aspx :

<html>
<head>
    <title>TASK 1</title>
</head>
<body>
    <p id="answer" style="font-size: 89px"></p>
    <script type="text/javascript">
        num1 = parseInt(prompt("Please enter num1:"));
        num2 = parseInt(prompt("Please enter num2:"));
        if (num1 > num2) {
            var ans = num1;
            document.getElementById("answer").innerHTML = "The biggest number is num1 and is equal to " + ans;
        }
        else if (num2 > num1) {
            var ans = num2;
            document.getElementById("answer").innerHTML = "The biggest number is num2 and is equal to " + ans;
        }
    </script>
</body>
</html>

Pretty simple JS code... I just wanted to know if it's possible to open the second aspx file (task2.aspx) right after the JavaScript code of task1 ends so it will open taks2 page in a new, blank page? Can U help me?


I tried some of the answers here but I actually wanted the new page to be opened in a new tab. Do you know how to do it?

Yuval
  • 7
  • 1
  • 6
  • You have conflicting statements *"open task2.aspx"* and *"open this page"*. Not really clear what you are trying to accomplish at a higher level. Take a look at [window.location](https://developer.mozilla.org/en-US/docs/Web/API/Window/location) methods – charlietfl Dec 25 '18 at 15:35
  • 1
    window.open('url/task2.aspx','_blank'); in the end of your script. – Sgedda Dec 25 '18 at 15:36
  • Possible duplicate of [Open URL in new window with Javascript](https://stackoverflow.com/questions/14132122/open-url-in-new-window-with-javascript) – Heretic Monkey Dec 25 '18 at 19:53

1 Answers1

0

You would want to use the window.open JavaScript with the _blank parameter.

The problem with what you are trying to do is user-experience. You do not want the user to get disorientated by showing a new page before they see the results of the first.

Depending on what you are trying to do/code, I would suggest a "next" button on task1 to let the user know they can now go to the "next" page. If this opens up a new window, all is good. Just my opinion though