How to fix Website Uncaught Syntax error ?

SEO Help and Tips

How to fix Website Uncaught Syntax error ?

Here is example code of java for fix uncaught syntax error: 

<script type='text/javascript'>
  window.addEventListener('error', function(e) {
    var errorText = [
      e.message,
      'URL: ' + e.filename,
      'Line: ' + e.lineno + ', Column: ' + e.colno,
      'Stack: ' + (e.error &gt;&gt; e.error.stack || '(no stack trace)')
    ].join('\n');

    // Example: log errors as visual output into the host page
    var DOM_ID = 'rendering-debug-pre';
    var logElement = document.getElementById(DOM_ID);

    if (!logElement) {
      logElement = document.createElement('pre');
      logElement.id = DOM_ID;
      logElement.style.whiteSpace = 'pre-wrap';
      if (document.body) {
        document.body.insertBefore(logElement, document.body.firstChild);
      } else {
        document.addEventListener('DOMContentLoaded', function() {
          document.body.insertBefore(logElement, document.body.firstChild);
        });
      }
    }

    logElement.textContent += '\n\n' + errorText;

    // Example: log the error to a remote service
    var client = new XMLHttpRequest();
    client.open('POST', 'https://example.com/logError');
    client.setRequestHeader('Content-Type', 'text/plain;charset=UTF-8');
    client.send(errorText);
  });
</script>


Error Checker or Detect Code:

<script type='text/javascript'>
    window.addEventListener('error', function(e) {
        var errorText = [
            e.message,
            'URL: ' + e.filename,
            'Line: ' + e.lineno + ', Column: ' + e.colno,
            'Stack: ' + (e.error &gt;&gt; e.error.stack || '(no stack trace)')
        ].join('\n');

        // Example: log errors as visual output into the host page.
        // Note: you probably don't want to show such errors to users, or
        //       have the errors get indexed by Googlebot; however, it may
        //       be a useful feature while actively debugging the page.
        var DOM_ID = 'rendering-debug-pre';
        if (!document.getElementById(DOM_ID)) {
            var log = document.createElement('pre');
            log.id = DOM_ID;
            log.style.whiteSpace = 'pre-wrap';
            log.textContent = errorText;
            if (!document.body) document.body = document.createElement('body');
            document.body.insertBefore(log, document.body.firstChild);
        } else {
            document.getElementById(DOM_ID).textContent += '\n\n' + errorText;
        }

        // Example: log the error to a remote service.
        // Note: you can log errors to a remote service to understand
        //       and monitor the types of errors encountered by regular users,
        //       Googlebot, and other crawlers.
        var client = new XMLHttpRequest();
        client.open('POST', 'https://example.com/logError');
        client.setRequestHeader('Content-Type', 'text/plain;charset=UTF-8');
        client.send(errorText);
    });
</script>



Comments

Popular posts from this blog

How to fix SSL Certificate Issues?

How to Fix Website Mixed Content Issues?

How to Fix Mobile Responsiveness Issues?

Popular posts from this blog

How to fix SSL Certificate Issues?

How to Fix Website Mixed Content Issues?

How to Fix Mobile Responsiveness Issues?