发布时间:2018-05-13作者:laosun阅读(2986)
仿CSDN等代码复制查看窗口, window.open弹出空页面,pre代码复制窗口。js向window.open传输数据。设置Html样式。 不需要重新创建window.open打开的页面,只需要用js向打开的页面设置html样式即可,非常的方便。
其实很简单,几句话的事
$(document).on('click','.copypre',function(){ var h = $(this).parent().parent().select(".container").find("div:not(':first')"); var content = ''; if(h!=null && h.length>0){ for(var i=0;i<h.length;i++){ content+=$(h[i]).text()+'\n'; } } var openWindow = window.open("about:blank", "view","width=600,height=450,menubar=no,toolbar=no, status=no,scrollbars=yes"); // openWindow.document.writeln('<html>'); // openWindow.document.writeln('<TITLE>Open Test</TITLE>'); // openWindow.document.writeln('<BODY>'); // openWindow.document.writeln('<center>'); // openWindow.document.writeln('Hello! New window opened!'); // openWindow.document.writeln('<br><br>'); // openWindow.document.writeln('<input type=button value=close onclick=window.close()>'); // openWindow.document.writeln('</center>'); // openWindow.document.writeln('</BODY>'); // openWindow.document.writeln('</HTML>'); openWindow.document.writeln('<textarea style="width:100%; height:100%">'+content+'</textarea>'); });
效果图如下:
版权属于: 技术客
原文地址: https://www.sunjs.com/article/detail/1f25fe2a753e40d39706428ad8e6071c.html
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
关键字: jquery 前端 源码 javascript