如何在新选项卡中打开DIV标记内的内容

vin*_*oth 5 html javascript jquery

$('.menu div.profile-btn').on('click', function () {
    $('.mainservice-page').fadeIn(1200);
}
Run Code Online (Sandbox Code Playgroud)

上面的脚本.mainservice-page成功打开了div的内容,但是我想在新选项卡中打开它们.

我怎样才能做到这一点?

提前致谢.

小智 5

你可以这样做:

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();

});
Run Code Online (Sandbox Code Playgroud)

希望这会帮助你.