Category:AutodeskQ:
How to specify a default object's unique id and a version number?
I would like to provide a client side template and version in the js string to make a link look like this:
Home
But I would like to be able to specify something like the following code.
window.location.href='#home?defaultVersion=3.12.12 and myClassName'"
Can this be done?
A:
You can use urlParams for this.
If you do not define a value for a given parameter it will be replaced by the parameter's default value.
As a demo I have replaced the version by a random number.
const version = '3.12.12';
const urlParams = new URLSearchParams();
let hash = window.location.hash;
// if there is a querystring in the url, use it
if (hash.indexOf('?') > -1) {
const [original] = hash.split('?');
// if there is no querystring, use the querystring of the url
if (original === '') original = window.location.search;
const [queryString] = original.split('&');
// if there is no querystring, use the default value
if (queryString === '') queryString = '?defaultVersion=' + version;
// update the querystring part of the url with the new value
urlParams.set('defaultVersion', version);
urlParams.set(queryString, '');
hash = `${original}${urlParams.get('defaultVersion')}`;
}
// if we have the url, just create a new url with the old url and add the url parameters
if (hash) {
urlParams.set('defaultVersion', version);
const newUrl = `${window.location.protocol}//${window.location.host} be359ba680
Related links:
Comments