window.open弹出空页面,pre代码复制窗口,不创建页面也能显示信息

发布时间:2018-05-13作者:laosun阅读(3141)

window.open弹出空页面,pre代码复制窗口,不创建页面也能显示信息

仿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>'); 
    });

    效果图如下:

    image.png


1 +1

版权声明

 jquery  前端  源码  javascript

 请文明留言

0 条评论