用于从另一个.aspx加载地图的Jquery解决方案?

时间:2013-02-20 14:07:48

标签: javascript jquery asp.net html css

尝试实现一个Jquery打印模板(C#ASP.net),它从我的Default.aspx获取我的地图并将其附加到打印页面(Print.htm),我可以编辑HTML。到目前为止......

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"</script>

  <script type="text/javascript">

  $(document).ready(function() {
  $("#Printbtn").click(function() {  

  var mapObj = $("MapCell_Map1");
  var mapHtmlStr = mapObj.html();

         mapHtmlStr = mapHtmlStr.replace(/CURSOR: crosshair; /g, "");
         mapHtmlStr = mapHtmlStr.replace("Maps['Map1'].pendingTiles.remove",          "return;");
         mapHtmlStr = mapHtmlStr.replace("Maps['Map1'].pendingTiles.remove", "return;");
         mapHtmlStr = mapHtmlStr.replace("Maps['Map1'].pendingTiles.remove", "return;");
         mapHtmlStr = mapHtmlStr.replace("Maps['Map1'].pendingTiles.remove", "return;");
         mapHtmlStr = mapHtmlStr.replace("Maps['Map1'].keyFocus=true;", "");


        $.ajax({url:"print.htm", context: document.body, 
        success: function(response){


        var printDoc = $(response);
        printDoc.find("#mapPanel").html(mapHtmlStr);
        var pwin = window.open("Print.htm");
        var pdoc = window.document.open();
        pdoc.write(printDoc.html());
        pdoc.close();

        });

        return false;

  });
  });     
</script>

不会触发,只需在按钮点击后发回...

<asp:Button runat="server" id="Printbtn" Text="Print" Forecolor="white"/>

Print.htm页面......

html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>


</head>
<body>
<div id="MapPanel">

</div>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

如果您要添加的Html是静态的,您可以将单独的Html文件加载到内存中,然后在将内容写入新窗口之前将动态Html添加到隐藏的div中

jQuery示例(未经测试):

function printmap() {
    var mapObj = $("#Map1");
    var mapHtmlStr = mapObj.html();
    // snip - do string replacements as shown in question
    $.ajax({url:"print.html", context: document.body, 
        success: function(response){
            var printDoc = $(response);
            printDoc.find("#mapPanel").html(mapHtmlStr);
            var pwin = window.open("#");
            var pdoc = window.document.open();
            pdoc.write(printDoc.html());
            pdoc.close();
    });
}

post中显示了在Javascript中加载Html文件的更多非jQuery示例: