0

Problem Statement: A User clicks on a button. It opens a new webpage in a new window. We check if the user has spent 5 seconds on this newly opened page. If yes, then page provides a link to another webpage. At last, the new webpage appears when the user clicks on the button. is it possible to do this in Javascript?

Things I know:

HTML:

<button onclick="timerPage()">Click me </button>

Javascript (in the head of the website)

<script type="text/javascript">
function timerpage()
{
window.open("timerPageUrl");
/* I believe after this point we don't have any control on this window.
Please correct me if I am wrong.
*/
}
</script>

I am able to create a "timer page with a click" separately but merging these two into one seems near to impossible to me. Well, I need some help.

Amninder Singh
  • 321
  • 1
  • 2
  • 20

2 Answers2

0

Take a look at the Mozilla documentation: https://developer.mozilla.org/en-US/docs/Web/API/Window/open

window.open returns a WindowProxy object which represents the newly created window.

In combination with settimeout you might be able to achieve what you want.

Rhapsody
  • 6,017
  • 2
  • 31
  • 49
  • Thanks for replying, so basically you are saying. On the button click. I open a new webpage and redirect that webpage to another page after say 5 seconds? – Amninder Singh Nov 03 '19 at 15:15
0

You need to run a script to append the new content to the page after certain time - 5 secs in your example - the steps depends on where you want to open the new window

the code needed to run in the new window is something like

window.setTimeout(function(){
 document.body.innerHTML = "<h1> this works after 5 secs! </h1>"
}, 500)
Mo3ty
  • 11
  • 4