Hi all,
Is it possible to fail a script if a javascript variable is not present in the source code of a page? How would this be done?
<html> <head> <title>My Page</title> <script> var myVar = Math.random() + ""; </script> </head> <body>...</body> </html>
Assuming the above page, how would I check that myVar exists & if it doesn't, fail the script.
I've tried this example, this example, window.myVar, gomez_top[0].myVar with no joy.
I will fail the script using this method.
Answer by Brett B. ·
Hey Adam,
Could you write a try/catch block around the line where you use the variable? Something like:
try{ myVar = Math.random() + ""; } catch(err){ log(err.message) }
I saw this w3schools example which changed the doc.innerHTML on a var not being set
DECEMBER 12, 10:00 AM GMT / 2:00 PM ET
Learn how Dynatrace Real User Monitoring automatically detects errors that impact your end users caused by erroneous 3rd party or CDNs.
December 10, 4:00 pm CET / 10:00 am ET
Register here
Learn how Dynatrace Real User Monitoring automatically detects errors that impact your end users caused by erroneous 3rd party or CDNs.
December 10, 4:00 pm CET / 10:00 am ET
Register here
Learn how Dynatrace Real User Monitoring automatically detects errors that impact your end users caused by erroneous 3rd party or CDNs.
December 10, 4:00 pm CET / 10:00 am ET
Register here