3

This doesn't work:

<a href='javascript:void(0)' target='_blank' onclick='do_stuff()' >Open</a>

And neither does this

<a href='javascript:void(0)' target='_blank'onclick='window.open(do_stuff(), "_blank");' >View</a>

It might be clear what I am trying to do. I need to open up a new tab with the results of a JavaScript function. Is there another way I can try to do this?

TheLettuceMaster
  • 15,594
  • 48
  • 153
  • 259

1 Answers1

5

Open new window (tab) and save it to a variable, then change it's content to your function output:

<button onclick="clicked()">Test</button>

<script>

var clicked = function () {
  var new_page = window.open();
  new_page.document.write("output");
}

</script>

You can use JS to create divs and change it's content:

new_page.document.getElementById('test').innerHTML = "test";
Marcin
  • 1,488
  • 1
  • 13
  • 27
  • I really like that jQuery option. Let me try and get back. – TheLettuceMaster Oct 13 '16 at 21:36
  • sorry, changed my code to JS and it should work now, will try to come up with a version for jQuery – Marcin Oct 13 '16 at 21:41
  • Thanks, this code works so I will mark as correct. However, as I explained above just now, I ended up not needing to dot his with my project as I misread my code a bit. Thanks for your help! I may use this in the future. – TheLettuceMaster Oct 13 '16 at 22:08