Reputation: 15734
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?
Upvotes: 3
Views: 4798
Reputation: 1494
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";
Upvotes: 5