displayHTML <a href="#id"> not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2025 01:01 AM
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>
""")
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2025 02:28 PM
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

