Fix #2033: Rstudio Viewer window not closed on shiny::stopApp()

This commit is contained in:
Joe Cheng
2018-05-03 14:06:34 -07:00
parent 9c3a0c86ca
commit c49a289619
5 changed files with 9 additions and 49 deletions

View File

@@ -141,30 +141,8 @@ var ShinyApp = function() {
};
this.$notifyDisconnected = function() {
// function to normalize hostnames
var normalize = function(hostname) {
if (hostname === "127.0.0.1")
return "localhost";
else
return hostname;
};
// Send a 'disconnected' message to parent if we are on the same domin
var parentUrl = (parent !== window) ? document.referrer : null;
if (parentUrl) {
// parse the parent href
var a = document.createElement('a');
a.href = parentUrl;
// post the disconnected message if the hostnames are the same
if (normalize(a.hostname) === normalize(window.location.hostname)) {
var protocol = a.protocol.replace(':',''); // browser compatability
var origin = protocol + '://' + a.hostname;
if (a.port)
origin = origin + ':' + a.port;
parent.postMessage('disconnected', origin);
}
if (window.parent) {
window.parent.postMessage("disconnected", "*");
}
};