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>
""")