Select to view content in your preferred language

I copy the html in arcgis sandbox, but cannot open it in any browsers? Do I miss anything? Thanks.

4508
16
04-15-2016 10:45 AM
JianShen1
Deactivated User

I am trying to create stand-alone html file using ArcGIS JavaScript API. I can see it in sandbox, but when I saved the content of the html to my local html file. I cannot display it in my browsers. Any help? Thanks.

By the way, I have web map ID from my arcgis online map. Thanks.

0 Kudos
16 Replies
RobertScheitlin__GISP
MVP Emeritus

Jian,

  Are you trying to view it using file:// in your browsers address bar? if so then you need to place the html file in a virtual directory on your machines IIS or place the file in the c:\inetpub\www folder and then use http://localhost/yourhtmlfilename.html

JianShen1
Deactivated User

Thanks. I tried per you suggestion, and it still failed. Actually I guess it may be caused by web map id part, please use this sample:

Web map by ID | ArcGIS API for JavaScript

//if accessing webmap from a portal outside of ArcGIS Online, uncomment and replace path with portal URL
      
//arcgisUtils.arcgisUrl = "https://pathto/portal/sharing/content/items";
        arcgisUtils
.createMap("4c009d4c236c4c0e91936b2fbfb085da","map").then(function(response){
         
//update the app
          dom
.byId("title").innerHTML = response.itemInfo.item.title;
          dom
.byId("subtitle").innerHTML = response.itemInfo.item.snippet;

you can try to copy the html content to create a stand-alone html file, and see how to open it with the browsers. I can open other sample without using web map id in my browsers, no matters where I saved that html file, this works:

Feature layer hover | ArcGIS API for JavaScript

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jian,

  I have taken that exact sample and copied the code to a html file on my development laptop and using the non file://  url it works great:

file:///C:/JS_Workspace/WebMap%20(2).html - does not show map

http://gislap183/js/WebMap%20(2).html - shows map just fine

0 Kudos
JianShen1
Deactivated User

I can show other maps without using web map id, but cannot see this one with web map

https://community.esri.com/external-link.jspa?url=https%3A%2F%2Fdevelopers.arcgis.com%2Fjavascript%2...

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jian,

  Like I said I can take that exact sample and copy it to my machine and if I use:

file:///C:/JS_Workspace/WebMap%20(2).html - does not show map

and if I use:

http://gislap183/js/WebMap%20(2).html - shows map just fine

Many other sample are file use file:///C:/JS_Workspace/whatever.html but that one is not.

Look at your browsers web console and you will see the error that is preventing you from using it.

It will be something like:

init.js:152 XMLHttpRequest cannot load file://www.arcgis.com/sharing/rest/content/items/4c009d4c236c4c0e91936b2fbfb085da?f=json. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

Which means you need to use http://machinename or http://localhost

0 Kudos
JianShen1
Deactivated User

Thanks. I put them in C:\inetpub\wwwroot, and used localhost. I did not get any response even errors from the html using web map, and I have no problems with the ones without using web map. Strange.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jian,

   And you opened your browsers developer tools (F12 button) and the web console did not report any errors?

0 Kudos
JenniferSwift
Occasional Contributor

The ArcGIS for Javascript API examples which include Web Map ID doe  not work outside of a sandbox, i.e: Web map by ID | ArcGIS API for JavaScript 3.18  - the samples do not work, nor do they work if replaced with other webmap ID's in ArcGIS online shared with Everyone.

What's really strange is that their maps are indeed shared, i.e.: https://www.arcgis.com/home/webmap/viewer.html?webmap=ef9c7fbda731474d98647bebb4b33c20 

The API samples simple don't work in any browser. But other sample code downloaded or copied work just fine.

Does anyone know why the Web Map ID sample code is broken?

Thanks, Jen

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jennifer,

   When you copy these to your local machine are you trying to run them with a file:// url or actuall using a proper http:// url?

0 Kudos