Spotfire Web Player Crash when triggering JavaScript via Anchor Tags (href="#").

Spotfire Web Player Crash when triggering JavaScript via Anchor Tags (href="#").

book

Article ID: KB0138256

calendar_today

Updated On:

Products Versions
Spotfire ALL

Description

When using custom JavaScript in a Text Area, a crash (Internal Error) may occur in the Spotfire Web Player when a user clicks a link or image designed to trigger a script.

Symptoms:

  • The script functions correctly in the Spotfire Analyst (Desktop Client).
  • The session crashes or displays an "Internal Error" immediately upon clicking the element in the Web Player.
  • The HTML for the trigger element usually utilizes an anchor tag with a hash reference, e.g., <a href="#">.

Cause:

This issue is caused by the difference in how the Spotfire Analyst (Desktop) and the Web Player (Browser) handle HTML navigation events.

  • Spotfire Analyst: The embedded browser often blocks or ignores default navigation events for anchor tags, allowing the attached JavaScript click event to execute without side effects.
  • Web Player: The browser treats <a href="#"> as a legitimate request to navigate (reload or jump to the top of the page). This default navigation behavior executes simultaneously with your custom JavaScript. This conflict interrupts the Web Player's session handling, leading to a crash.

Environment

All

Resolution

To resolve this, you must prevent the browser's default navigation action when the click event is triggered. You can achieve this in two ways:

Method 1: Use event.preventDefault() (Recommended)

Update your JavaScript to accept the event argument and call preventDefault() at the beginning of the function.

Incorrect Code (Causes Crash):

$("#myButton").click(function(){

   // Your code here

   $("#myInput").val("Test");

});

Corrected Code:

$("#myButton").click(function(event){

   event.preventDefault(); // Stops the browser from following the href

      // Your code here

   $("#myInput").val("Test");

});

 

Method 2: Use a different HTML element

Avoid using the <a> (anchor) tag if the element is not actually a link to another page. Instead, use a <span>, <div>, or <button> and style it using CSS to look like a link if necessary. These elements do not have a default navigation behavior.

HTML Example:

  • Change:
    <a id="myButton" href="#">Click Here</a>
  • To:
    <span id="myButton" style="cursor:pointer; color:blue;">Click Here</span>

Issue/Introduction

When using custom JavaScript in a Text Area, a crash (Internal Server Error) may occur in the Spotfire Web Player when a user clicks a link or image designed to trigger a script. This issue arises because the Web Player processes the default browser navigation event simultaneously with the custom script.

Additional Information

External: MDN Web Docs: