Created
August 11, 2023 10:02
-
-
Save vernetto/de0c23f826ffae098b5486c483f5daca to your computer and use it in GitHub Desktop.
entity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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