我需要你的帮助,我试图在javascript中弹出一个新窗口。新窗口将包含父窗口的信息。我在div中添加了所有内容。 调用脚本的按钮如下所示。
<asp:Button ID="Button6" OnClientClick="PrintElem('#info1');" CssClass="btn btn- primary btn-xs" runat="server" Text="Print Report"/>
我有一个div可以包含我要在新窗口中显示的所有内容
<div id="info1" runat="server">
这个想法是我不想显示页面的菜单。我只是希望在新窗口中显示特定的div内容。当我点击按钮时,它显示一个空页面抛出一个UNDEFINED异常。谢谢你的帮助。
这是我的剧本。
function PrintElem(elem) {
Popup($(elem).html());
}
function Popup(Data) {
var mywindow = window.open('', 'my div', 'height=1000,width=1200');
mywindow.document.write('<html><head><title>Report Title</title>');
// mywindow.document.write('<link href="/Content/bootstrap/css/bootstrap.min.css" rel="stylesheet" media="all" /> <link href="/Content/assets/css/plugins/jquery-ui.css" rel="stylesheet" media="all" /> <link href="/Content/assets/css/main.css" rel="stylesheet" media="all" /> <link href="/Content/assets/css/plugins.css" rel="stylesheet" media="all" /> <link href="/Content/assets/css/icons.css" rel="stylesheet" media="all" /> <link href="/Content/assets/css/fontawesome/font-awesome.min.css" rel="stylesheet" media="all" />');
mywindow.document.write('</head><body>');
mywindow.document.write(Data);
mywindow.document.write('</body></html>');
mywindow.print();
//mywindow.close();
return true;
}
答案 0 :(得分:0)
试试这个:
var mywindow = window.open('', 'my div', 'height=1000,width=1200,toolbar=no,menubar=no,scrollbars=no,resizable=no');
编辑:以下内容适用于我:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test</title>
<script type="text/javascript">
function Popup(Data) {
var mywindow = window.open('', 'my div', 'height=1000,width=1200');
mywindow.document.write('<html><head><title>Report Title</title>');
// mywindow.document.write('<link href="/Content/bootstrap/css/bootstrap.min.css" rel="stylesheet" media="all" /> <link href="/Content/assets/css/plugins/jquery-ui.css" rel="stylesheet" media="all" /> <link href="/Content/assets/css/main.css" rel="stylesheet" media="all" /> <link href="/Content/assets/css/plugins.css" rel="stylesheet" media="all" /> <link href="/Content/assets/css/icons.css" rel="stylesheet" media="all" /> <link href="/Content/assets/css/fontawesome/font-awesome.min.css" rel="stylesheet" media="all" />');
mywindow.document.write('</head><body>');
mywindow.document.write(Data);
mywindow.document.write('</body></html>');
mywindow.print();
//mywindow.close();
return true;
}
</script>
</head>
<body>
<button onclick="Popup('Hahaha');">Go Popup</button>
</body>
</html>