Hi Charlie,

in general the first thing to do in such a case is to use the search engine 
of your choice and look for a polyfill for the "offending" code, which 
often thanks to a lot of wonderful people already exists.

In your case though since you are only using this in one place for one 
parameter - at least for the moment  - it would probably be overkill to 
import a complete polyfill for urlsearchparams into your wiki. So I did 
what Mark suggested and rewrote your function to get the context from 
location.search via regex.
Please be aware that this is neither necessarily best practice nor tested 
beyond a general it works as I currently don't have access to my testing 
setups to see if it works in IE11 specifically, although in theory it 
should as everything used is supported by it.
Also I went a bit overboard and changed how the context is checked so it 
assumes the default context until the loop finds that the parameter is a 
valid context and resets it. This was mostly done as to have one place to 
add contexts/change the default context while being able to leave the rest 
of the code alone. If you want to keep your if check because it is easier 
for you to use I can rewrite the function to use that instead.


exports.run = function() {
  /* Settings */
  const contexts = [
    "ProductReviews",
    "OffGridding",
    "HydroCutting",
    "Chromebook",
  ];
  const defaultContext = "ProductReviews";
  const ctxre = /context=(\w+)/i;

  let currentContext = defaultContext;
  const queryString = window.location.search;
  const match = queryString.match(ctxre);
  if(match){
    let tmpContext = match[1];
    for(let i = 0; i < contexts.length; i++){
      if(contexts[i] == tmpContext){
        currentContext = tmpContext;
        break;
      }
    }
  }
  
  document.title = currentContext;
  return currentContext;
};


Hope this helps.
Felicia



On Monday, 26 October 2020 23:47:28 UTC+1, Charlie Veniot wrote:
>
> G'day,
>
> Javascript and I have never gotten along, but once in a while I've got no 
> choice have simply must surrender to it.
>
> Working on my Chromebook, when I get something working, I never think of 
> making sure it works with other browsers.  Sure enough, I discovered today 
> that some javascript in my TiddlyWiki doesn't work with Internet Explorer.
>
> Specifically, the offending bit of code: a call to URLSearchParams.
>
> Figuring that I want error-handling that simply/gracefully/quietly exits 
> the code, I decided to wrap all of the code with "try" and "catch" 
> processing (having just discovered that today).
>
> If anybody has any related experience and/or interesting/educative info to 
> share: please please please ?
>
> Related snipit of code (from this TiddlyWiki's tiddler 
> <https://intertwingularityslicendice.neocities.org/CJ_ProductReviews.html#%24%3A%2Fmacros%2Fcharlie%2Fgetstartupcontext.js>)
>  
> further below.
>
> Cheers !
>
> exports.run = function() {
>         const queryString = window.location.search;
> try {
>         const urlParams = new URLSearchParams(queryString);
>         const wikicontext = urlParams.get('context');
>         var output = wikicontext;
>
>         if ( (output !== "OffGridding") && (output !== "HydroCutting")  && 
> (output !== "Chromebook") ){
>             output = "ProductReviews";
>         };
>           document.title = output;
> }
> catch(err) {
>             output = "ProductReviews";
> }
>         return output;
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/8be5771e-60e9-4dc0-9170-e510233348a3o%40googlegroups.com.

Reply via email to