在新窗口中打开页面上的 div,同时保持通过 websockets 更新它的能力 [英] Open a div on the page in a new window while maintaining the ability to update it via websockets

查看:9
本文介绍了在新窗口中打开页面上的 div,同时保持通过 websockets 更新它的能力的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在新窗口(新浏览器窗口)中打开页面的一部分(我有通知的地方),同时保持获取 websocket 更新的能力,以便在更新时可以在两个窗口上接收通知.

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.

我想知道是否可以使用 jQuery 或任何其他方法来做到这一点.如果重要的话,我使用的框架是支柱.

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!

推荐答案

尝试

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/

这篇关于在新窗口中打开页面上的 div,同时保持通过 websockets 更新它的能力的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆