cancel
Showing results for 
Search instead for 
Did you mean: 
Administration & Architecture
Explore discussions on Databricks administration, deployment strategies, and architectural best practices. Connect with administrators and architects to optimize your Databricks environment for performance, scalability, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 

displayHTML <a href="#id"> not working

invalidargument
New Contributor III

Many packages output a html-report, e.g. ydata-profiler. The report contains links to other parts of the report. But when the user clicks the links a new window is opened instead of scrolling to the correct section of the displayed html.

Could this be fixed from the databricks end somehow?

Example:

displayHTML("""
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Example HTML</title>
</head>
<body>
    <h1 id="example">Example Header</h1>
    <p>This is an example paragraph with a <a href="#example">link to the header</a>.</p>
</body>
</html>
""")

 

There is a workaround to do inject javascript. Example with workaround:

displayHTML("""
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Example HTML</title>
</head>
<body>
    <h1 id="example">Example Header</h1>
    <p>This is an example paragraph with a <a href="#example">link to the header</a>.</p>

    <script>
        document.querySelectorAll('a[href^="#"]').forEach(el => {
            el.onclick = function(event) {
                event.preventDefault();
                document.querySelector(this.getAttribute('href')).scrollIntoView({ behavior: 'smooth' });
            };
        });
    </script>
</body>
</html>
""")
1 REPLY 1

Alberto_Umana
Databricks Employee
Databricks Employee

Hello @invalidargument,

Currently, there is no direct support from the Databricks end to modify this behavior without using such a workaround. The displayHTML function in Databricks renders HTML content within an iframe, and the injected JavaScript handles the link behavior within that iframe

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group