Open a div on the page in a new window while maint

2019-02-28 04:10发布

I am trying to have a section of the page (where i have notifications) open in a new window (new browser window) while maintaining the ability to get websocket updates so the notifications can be received on both windows when something gets updated.

I am wondering if there is anyway to do this using jQuery or any other method. The framework I am using is backbone if that matters.

Thanks in advance for any ideas!

1条回答
贼婆χ
2楼-- · 2019-02-28 04:18

Try

html

<textarea placeholder="click `open popup`
to open and update"></textarea>
<br />
<input type="button" value="open">
<input type="button" value="close">

js

$(function () {
    $("input[value=open]").focus().one("click", function () {
        $("body").append("<br /><span class=update></span>");
        var popup = window.open("", "popup", "width=200, height=100");
        popup.document.write("popup ready");
        $(".update").html("popup ready");
        popup.focus();

        $("textarea").on("change", function (e) {
            popup.document.write($(this).val() + "<br />");
            $(".update").html(function (i, o) {
                return o + $(e.target).val() + "<br />";
            });
            $(this).val("");
            return popup.focus();
        }).change();

        $("input[value=close]").on("click", function () {
            popup.close();
            return $("textarea").attr("placeholder", "popup closed");
        });
        return $("textarea").attr("placeholder", "popup ready to update");
    });    
});

jsfiddle http://jsfiddle.net/guest271314/b2e7t/

查看更多
登录 后发表回答