Skip to content

Instantly share code, notes, and snippets.

@vernetto
Created August 11, 2023 10:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vernetto/de0c23f826ffae098b5486c483f5daca to your computer and use it in GitHub Desktop.
Save vernetto/de0c23f826ffae098b5486c483f5daca to your computer and use it in GitHub Desktop.
entity
switchEntityId: function(entityId) {
// Step 1: Validate the entityId. This is just a basic example, adapt as needed.
if (!isValidEntityId(entityId)) {
console.error('Invalid entityId:', entityId);
return;
}
// Steps 2 & 3: Use URL and URLSearchParams to safely manipulate the URL
let currentUrl = new URL(window.location.href);
let urlParams = new URLSearchParams(currentUrl.search);
urlParams.set('bla', entityId);
currentUrl.search = urlParams.toString();
window.location.href = currentUrl.toString();
}
function isValidEntityId(entityId) {
// Implement your own validation logic here. This is just a placeholder.
return typeof entityId === 'string' && entityId.length < 100; // for example, check if it's a string and not too long
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment