Lefteris, Here are my corrections to the tool.html.
- Notice I do not have index.js as you did, as this would create a second instance of that JS file in another scope.
- No need for any JS API links
- I call window.opener to get a reference to the code that opened this window
<html>
<head>
<script>
document.cookie = "Set-Cookie: flavor=choco; SameSite=None; Secure"
function test() {
url = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0"
window.opener.check(url)
}
</script>
</head>
<body>
<div id="demo">
<h2>Testing</<h2>
</div>
<button onclick="test()">Load</button>
</body>
</html>
Next the index.js changes:
- No need for global vars once the fixes to the tool.html are applied
check = null
trailheadsLayer = null
require([
"esri/Map",
"esri/views/MapView",
"esri/layers/FeatureLayer"
], function (Map, MapView, FeatureLayer) {
esrimap = new Map({
basemap: "topo-vector"
});
view = new MapView({
container: "viewDiv",
map: esrimap,
center: [-118.80543, 34.02700],
zoom: 13
});
check = function check1(value) {
trailheadsLayer = new FeatureLayer({
url: value
});
if (trailheadsLayer) {
esrimap.add(trailheadsLayer)
}
}
});