summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVenugopal Shivashankar <venugopal.shivashankar@digia.com>2015-12-22 13:28:10 +0100
committerVenugopal Shivashankar <venugopal.shivashankar@digia.com>2016-01-04 14:33:42 +0000
commite82b9c37609ab8f686a6dfd312bf0423bb740f35 (patch)
tree6214c5b2919b233e8eb339b461a0c91bf2563116
parent97577a0f27a1f427948871ae535645a2e0788bf7 (diff)
downloadqtwebchannel-e82b9c37609ab8f686a6dfd312bf0423bb740f35.tar.gz
Example: Modify JavaScript part of the HTML
The baseUrl that is used to connect to a WebSocket server is derived from the query parameters set to the URL. These parameters are ignored by the QDesktopServices::openUrl implementations specific to Windows and OS X. Ubuntu uses the default implementation that retains the query parameters. This means the browser instance will fail to open the local file URL on Ubuntu because it includes the query parameters, so query parameters should never be set. Moreover, the example creates a QWebSocketServer instance, which is available at ws://localhost:12345, so the it is safe to hardcode the address in the JavaScript. The cleaner approach would be to use a URLHandler as described in http://doc.qt.io/qt-5/qdesktopservices.html#url-handlers, but that complicates the example. Change-Id: I5b5df2b7b816ce0bbfb16a85c036ed379616f04a Task-number: QTBUG-46541 Reviewed-by: Milian Wolff <milian.wolff@kdab.com>
-rw-r--r--examples/webchannel/standalone/index.html5
-rw-r--r--examples/webchannel/standalone/main.cpp1
2 files changed, 4 insertions, 2 deletions
diff --git a/examples/webchannel/standalone/index.html b/examples/webchannel/standalone/index.html
index 778a502..cc3d72d 100644
--- a/examples/webchannel/standalone/index.html
+++ b/examples/webchannel/standalone/index.html
@@ -11,7 +11,10 @@
output.innerHTML = output.innerHTML + message + "\n";
}
window.onload = function() {
- var baseUrl = (/[?&]webChannelBaseUrl=([A-Za-z0-9\-:/\.]+)/.exec(location.search)[1]);
+ if (location.search != "")
+ var baseUrl = (/[?&]webChannelBaseUrl=([A-Za-z0-9\-:/\.]+)/.exec(location.search)[1]);
+ else
+ var baseUrl = "ws://localhost:12345");
output("Connecting to WebSocket server at " + baseUrl + ".");
var socket = new WebSocket(baseUrl);
diff --git a/examples/webchannel/standalone/main.cpp b/examples/webchannel/standalone/main.cpp
index 8005301..9c03370 100644
--- a/examples/webchannel/standalone/main.cpp
+++ b/examples/webchannel/standalone/main.cpp
@@ -132,7 +132,6 @@ int main(int argc, char** argv)
// open a browser window with the client HTML page
QUrl url = QUrl::fromLocalFile(BUILD_DIR "/index.html");
- url.setQuery(QStringLiteral("webChannelBaseUrl=") + server.serverUrl().toString());
QDesktopServices::openUrl(url);
dialog.displayMessage(QObject::tr("Initialization complete, opening browser at %1.").arg(url.toDisplayString()));