Skip to content

Instantly share code, notes, and snippets.

@fongreecss
Created May 22, 2023 07:36
Show Gist options
  • Save fongreecss/9d9548430c960f42c118d76fa8242cf5 to your computer and use it in GitHub Desktop.
Save fongreecss/9d9548430c960f42c118d76fa8242cf5 to your computer and use it in GitHub Desktop.
Redirect cities in Philadelphia to another landing page (using geojs.io)
<!-- The GeoJS script is loaded asynchronously. -->
<script async src="https://get.geojs.io/v1/ip/geo.js"></script>
<!-- A function is defined to handle the JSON response from the GeoJS API. -->
<script type="application/javascript">
function geoip(json) {
// The JSON data returned from GeoJS is parsed and the relevant fields are extracted and assigned to variables.
const cities = [
"Abington",
"Ambler",
"Blue Bell",
"Broomall",
"Bryn Mawr",
"Chester",
"Collegeville",
"Downingtown",
"Doylestown",
"Dublin",
"Exton",
"Flourtown",
"Fort Washington",
"Glenside",
"Harleysville",
"Hatboro",
"Havertown",
"Honey Brook",
"Horsham",
"Huntingdon Valley",
"Kennett Square",
"Lansdale",
"Malvern",
"Media",
"Morrisville",
"Norristown",
"North Wales",
"Paoli",
"Pennsburg",
"Philadelphia",
"Phoenixville",
"Pipersville",
"Plymouth Meeting",
"Pottstown",
"Quakertown",
"Ridley Park",
"Schwenksville",
"Secane",
"Sellersville",
"Southampton",
"Spring House",
"Telford",
"Warminster",
"West Chester",
"West Grove",
"Willow Grove",
"Wyndmoor",
"Yardley"
];
const country = "PA"
if(cities.includes(json.city)) {
window.location.href = "/philly";
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment