justin m justin m - 1 year ago 93
HTML Question

javascript works in sandbox but not in browser

I put together this code to produce a map centered on a location and tested it with multiple sandbox applications and it works, but when I try to run it from a .html file on my desktop the page is blank. Does anyone have any ideas on what i'm doing wrong?

<!DOCTYPE html>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user- scalable=no">
<title>OKC MapView - Create a 2D map - 4.1</title>
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;

<link rel="stylesheet" href="https://js.arcgis.com/4.1/esri/css/main.css">
<script <!-- src="https://js.arcgis.com/4.1/"> //--></script>

], function(Map, MapView) {

var map = new Map({
basemap: "togo"

var view = new MapView({
container: "viewDiv",
map: map,
zoom: 10,
center: [-97.508, 35.482]


<div id="viewDiv"></div>

Answer Source

Are you trying to open the file directly as file:/// then it might not work, as you need to host it in a website.

There is no service by name "togo" it needs to be "topo".

Also, get rid of the un-necessary comments <!-- -->

Hope this was helpful.