我可以得到SignalR不切断自己,当设置窗口的位置? [英] Can I get SignalR to not disconnect itself when settings window location?

查看:157
本文介绍了我可以得到SignalR不切断自己,当设置窗口的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写听SignalR,一旦发现将在我们的服务器上执行一个Ajax请求的Web服务事件一个简单的页面。

I am writing a simple page that listens to SignalR events that once detected will perform an ajax request to a web service on our servers.

一旦Ajax请求完成后,URL与一个自定义的URI方案,一旦reirected来,将打开安装在客户端计算机上的自定义程序,而不从主页导航离开返回。这是通过调用了window.location = URL来实现;在Ajax请求的成功回调

Once that ajax request is complete, a url is returned with a custom URI scheme that once reirected to, will open up a custom program installed on the client machine without navigating away from the main page. This is achieved by calling window.location = url; in the success callback of the ajax request.

此方法适用找到我们的网站上,我们正在使用此的其他领域,进行多Ajax请求,并在不影响主网页发送命令到我们的程序在回调重定向的工作,因为它应该。

This method works find on the other areas of our website that we are using this, making multiple ajax requests and redirecting in the callback work as it should by sending commands to our program without affecting the main page.

新页面不过,我创建使用SignalR来决定何时,以使这些相同的Ajax请求,但它是在第一重定向断开本身。我觉得在JavaScript控制台我了解以下信息是很正常的看到,当一个页面被卸载,但在我的情况的情况下,调用页面不会真正卸载:连接到...被中断,而该网页加载。

The new page I am creating however uses SignalR to decide when to make these same ajax requests but it is disconnecting itself upon the first redirect. I find the following message in the javascript console which I understand is quite normal to see when a page is unloaded but in the case of my scenario, the calling page is never actually unloaded: The connection to ... was interrupted while the page was loading.

我要寻找一种方法来阻止SignalR从重定向断开本身,因为这会导致进一步重定向到失败,直到SignalR重新建立连接。

I am looking for a way to stop SignalR from disconnecting itself on the redirect as this causes further redirects to fail until SignalR re-establishes the connection.

推荐答案

SignalR尝试当用户离开该页面以正常停止所有正在进行的连接。 SignalR通过结合使用jQuery窗口卸载事件做到这一点。通常这是用做 $(窗口).bind(卸载,//...,但在Firefox $(窗口).bind (beforeunload,//...也被使用。

SignalR tries to gracefully stop any ongoing connections when the user navigates away from the page. SignalR does this by binding to window unload events using jQuery. Typically this is done using $(window).bind("unload", //..., but in Firefox $(window).bind("beforeunload", //... is also used.

假设你没有连接到这些事件的话,你可以通过取消绑定使用jQuery受SignalR卸载和beforeunload事件处理程序prevent这种行为:

Assuming you don't attach to either of these events yourself, you can prevent this behavior by unbinding the unload and beforeunload event handlers bound by SignalR using jQuery:

$(window).unbind("unload");
$(window).unbind("beforeunload");

这篇关于我可以得到SignalR不切断自己,当设置窗口的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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