admin管理员组文章数量:1026989
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";
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";
本文标签: htmlOpen New Tab with Results from JavaScript functionStack Overflow
版权声明:本文标题:html - Open New Tab with Results from JavaScript function - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745609247a2158905.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论