Skip to content

Instantly share code, notes, and snippets.

@AlainODea
Created August 4, 2018 15:08
Show Gist options
  • Select an option

  • Save AlainODea/35a33b21ac6947990bebee4e2b980d79 to your computer and use it in GitHub Desktop.

Select an option

Save AlainODea/35a33b21ac6947990bebee4e2b980d79 to your computer and use it in GitHub Desktop.
CORS from file:// origin
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>What is my IP?</title>
<script type="text/javascript">
function reqListener () {
var response = JSON.parse(this.responseText);
document.getElementById("ip").innerText =
'Your public IP is ' + response.origin;
}
var oReq = new XMLHttpRequest();
oReq.addEventListener("load", reqListener);
oReq.open("GET", "https://nghttp2.org/httpbin/ip");
oReq.send();
</script>
</head>
<body>
<h1>What is my IP?</h1>
<div id="ip">Calculating your public IP...</div>
</body>
</html>
@AlainODea

Copy link
Copy Markdown
Author

This may cease to work in future.

This file successfully makes the CORS request when downloaded and run locally in:

  • Firefox 61.0.1
  • Chrome 68.0.3440.84
  • Safari 11.1.2 (12605.3.8.1)
  • Edge 41.16299.551.0

@AlainODea

Copy link
Copy Markdown
Author

This does not work (without user clicking Allow Restricted Content) in Internet Explorer 11.551.16299.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment