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
1 Answer
Reset to default 5Open 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条)