dimanche 27 septembre 2020

Under what conditions would window.location.search be undefined?

We inconsistently see this error in our logs: Cannot read property 'substring' of undefined

It occurs on this line of code: var sPageURL = window.location.search.substring(1)

Unfortunately, the error is not consistently reproduced, but the flow is:

  1. Open new window via JavaScript.

  2. In new window, invoke this line of code.

Based on Googling, internal testing, and answers like this, it seems like window.location.search should at worse but the empty string, but never undefined. If window or location were undefined, then it would be expected for the error to appear differently.

Under what conditions could window.location.search be undefined?




Aucun commentaire:

Enregistrer un commentaire