开发者

re-rendering html in a div to a new browser window

开发者 https://www.devze.com 2023-04-01 21:37 出处:网络
I would like to take all my <div>\'s in a parent <div> and re-render the contents into a new broswer window.Can anyone make any suggestions?I\'m 开发者_JS百科using jQuery and .NET.

I would like to take all my <div>'s in a parent <div> and re-render the contents into a new broswer window. Can anyone make any suggestions? I'm 开发者_JS百科using jQuery and .NET.

  1. Get all divs in the markup.

    var markupData = $("#names").html();
    
  2. Empty div.

    $("#names").empty();
    
  3. open new window displaying markupData.

    ???
    


How about:

var html = $("#names").html();
var my_window = window.open("", "mywindow1", "width=350,height=150");

$(my_window.document).find("body").html(html);

Using window.open. Keep a reference to the window you just created and set its HTML.

Example: http://jsfiddle.net/A72TH/


If you wanted to append a stylesheet containing CSS rules for the blank page, you could write something like this:

$(my_window.document)
    .find("head")
    .append("<link rel='stylesheet' href='styles.css' />");


Sounds like you want to make an instance of a new window and then write to it with your data. Here is a helpful link for that:

http://www.javascripter.net/faq/writingt.htm

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号