On this page
It’s possible to pass data to the HTML page. The mechanism depends on how you launch the page. See the Launching URLs task page for more info on how to launch your page.
Adding query parameters to the URL being shown
This will work with all ways of launching and showing HTML pages.
return {
"url": "//www.esri.com/sample.html",
...
// Provide a query parameter of name value pairs
"query": {
"valueA": "Value A",
"valueB": "Value B"
}
}
Sending a POST request to get the page
To send a POST request to a server and show the responding page, use the following script:
If you send through a complex form, only the top level parameters will be sent. The values will be converted to strings. If those parameters are FeatureSets, all the data will be retrieved and converted into a string.
return {
"url": "//www.esri.com/sample.html",
...
"method": "post"
// Provide the form parameter of name value pairs
"form": {
"valueA": "Value A",
"valueB": "Value B"
}
}
Opening a page with pipe
Opening a page with the pipe
method means that data will be sent to the page using window.postMessage
. The messages sent are specific to Sweet. This approach allows the page to receive data from the application and to send messages back again.
return {
"url": "//www.esri.com/sample.html",
...
"method": "pipe"
// Provide the data to be 'piped' to the page. This will be converted to a JSON object
"form": {
"valueA": "Value A",
"valueB": "Value B"
}
}
The following can be added to the HTML page to receive the data:
// Receives a message from the parent window and runs the command
function handleCommand(json) {
// Function to handle the data piped to the page
}
function receiveMessage(event) {
// Keep source and origin, to send requests back again.
var source = event.source;
var origin = event.origin;
if (event.data.startsWith("notifysizing:")) {
// Event, to say the parent window wants to be notified of size changes to the page
return;
}
if (event.data.startsWith("update:")) {
// Event to say the parent window wants to update the contents of the page, as feedback has changed
// will only get fired if 'preserve' is set to true, in the feedback configuration.
var json = JSON.parse(event.data.substr(7));
handleCommand(json);
return;
}
var json = JSON.parse(event.data);
handleCommand(json);
}
window.addEventListener("message", receiveMessage, false);
// If the window has been opened in a new tab, then need to send
// back the details, to allow Sweet for ArcGIS to communicate.
if (window.opener) {
window.opener.postMessage(JSON.stringify({ opened: window.name }), "*");
}