Do something different based on multiple different URL parameters
I have the following script started and need to trigger certain modals to open on page load, based on the URL string. For example, if 'src' is equal to '123', then modalBuyer needs to appear. If 'src' is equal to '234', then modalSeller needs to appear. Here's what I have so far. This was created back when there was only one modal that ever needed to be shown on page load.
- if (window.location.href.indexOf('src=') > 0) {
- $(window).on('load',function(){
- $('#cModal').modal('show');
- });
- }
I was considering doing something like this, but was curious if there might be a better way:
- var src= (new URL(location)).searchParams.get('src')
- var SRC_LOOKUP = {
- 123: "modalBuyer",
- 234: "modalSeller",
- }