Can't open my app with url scheme

Hello I made webpage that redirect to my app.
I made function to open market page.

what I think it’s weird is that I made code that after 2second page loaded, it automatically call function that redirect market page. but it won’t
what is really weird is that by pressing button , it trigger same function. but then it redirect to market page.

why not redirect automatically , but I should press button?

  //get parameter로 부터 받은 값

  function goto(){
    console.log("come to goto");
    var market_url = "market://details?id=io.ionic.onofflab.bilim";

  <button id="btn" onclick="javascript:goto();"> go to app</button>