html - Open New Tab with Results from JavaScript function - Stack Overflow

This doesn't work:<a href='javascript:void(0)' target='_blank' onclick=

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?

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?

Share Improve this question asked Oct 13, 2016 at 21:16 TheLettuceMasterTheLettuceMaster 15.8k51 gold badges158 silver badges266 bronze badges 9
  • 1 What results are you trying to pass to new window? – guest271314 Commented Oct 13, 2016 at 21:19
  • @guest271314 just HTML. – TheLettuceMaster Commented Oct 13, 2016 at 21:22
  • Can you show your code for do_stuff()? – Polynomial Proton Commented Oct 13, 2016 at 21:22
  • do_stuff() calls ajax and returns HTML. Not much more than that. the return function populates something like $("#myDiv").html(data); – TheLettuceMaster Commented Oct 13, 2016 at 21:25
  • Have you checked this answer for HTML content using window.open. Might help – Polynomial Proton Commented Oct 13, 2016 at 21:27
 |  Show 4 more ments

1 Answer 1

Reset to default 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";

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745609248a4635850.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信