如何在新标签页中打开DIV标签内的内容

6
$('.menu div.profile-btn').on('click', function () {
    $('.mainservice-page').fadeIn(1200);
}

上述脚本成功地打开了 .mainservice-page div 的内容,但我想在新标签页中打开它们。
我该怎么做?
提前感谢。

你是指浏览器标签页吗? - Lucius
这是一个类似的线程: https://dev59.com/QW865IYBdhLWcg3wYNnj - Thamilhan
你是否打开了任何URL,或者你只想在浏览器的新标签页中打开内容?这个类“mainservice-page”包含完整的页面还是只包含内容。 - Manoj Srivastava
1个回答

6
您可以像这样操作:
function newWindow_method_1() {
  var wi = window.open();
  var html = $('.mainservice-page').html();
  $(wi.document.body).html(html);
}
OR
function newWindow_method_2() {

  var html = $('.mainservice-page').html();
  window.open(html, "__new", "width=1000,height=1000");

}

$('.menu div.profile-btn').on('click', function () { 
  newWindow_method_1();

 // OR

 // newWindow_method_2();

});

希望这能帮到您。

@Manoj Srivastava 工作得非常好。谢谢你。 - Stack Overflowerrr
感谢 @StackOverflowerrr - Manoj Srivastava
工作的答案,但有一个问题,如果我们在jQuery中设置了一些HTML控件的值,然后打开新标签页中的div,那么所有设置的值会显示在新标签页中吗? - user3497034

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接