Javascript button open function [duplicate]

I want to open the function make_table() on click the button, but I don’t find how to do this, this is my code:

var x = document.querySelectorAll("a");
var myarray = []
var alllinks = []
for (var i = 0; i < x.length; i++) {
  var nametext = x[i].textContent;
  var cleantext = nametext.replace(/s+/g, ' ').trim();
  var cleanlink = x[i].href;
  alllinks.push([cleantext, cleanlink]);
};

function make_table() {
  var table = '<table><thead><th>Name</th><th>Links</th></thead><tbody>';
  for (var i = 0; i < myarray.length; i++) {
    table += '<tr><td>' + myarray[i][0] + '</td><td>' + myarray[i][1] + '</td></tr>';
  };

  var w = window.open("");
  w.document.write(table);
}
var button = document.createElement("Button");
button.innerHTML = "Links AP y EP";
button.style = "position:absolute;z-index: 1;top: 85px;right: 60px;"
document.body.appendChild(button);
button.addEventListener("click", function() {});