Hi all,

Question is, Is it possible to make a tool tip based on the content saved in a .txt file? If yes, Can you please tell me how?


Regards,

Sameer.

Dani AI

Generated

Yes — tooltip text can be loaded from a .txt file. Two common patterns are: server-side rendering (read the file and emit HTML when the page is generated) and client-side fetching (load the .txt on hover/click and inject it into a tooltip element). ’s PHP answer shows the server-side route; pointed toward jQuery-based client solutions. Both are valid—choice depends on whether tooltip content is static or must be loaded on demand.

A minimal, safe client-side pattern uses the Fetch API and injects text as plain text (not HTML) to avoid XSS. The example below shows the idea; error handling, caching, and UX (delay, spinner) should be added as needed. See MDN: Using Fetch and prefer textContent over innerHTML (MDN: textContent).

el.addEventListener('mouseenter', async () => {
  try {
    const res = await fetch('/tips/term1.txt');
    if (!res.ok) throw new Error('Not found');
    tooltip.textContent = await res.text();
    showTooltip(tooltip, el);
  } catch {
    tooltip.textContent = 'Tip unavailable';
  }
});

For minimal ASP.NET code (answering ), expose a tiny endpoint that returns the file as text/plain, sanitizing the requested name to prevent directory traversal and only serving from a dedicated tips folder. In MVC/Core a compact action looks like:

public IActionResult Tip(string name)
{
    var safe = Path.GetFileName(name); // sanitize
    var path = Path.Combine("tips", safe + ".txt");
    if (!System.IO.File.Exists(path)) return NotFound();
    var text = System.IO.File.ReadAllText(path);
    return Content(text, "text/plain");
}

Accessibility and security notes: follow the WAI‑ARIA tooltip pattern (WAI‑ARIA examples), ensure correct MIME (text/plain), validate filenames server-side, and use caching headers so repeated requests don’t overload the server.

Recommended Answers

All 3 Replies

You could try PHP - something like this:

<?php
// Write out ToolTip.txt file
if ($handle = opendir("path_to_dir_containing_file")) {
    while (false !== ($file = readdir($handle))) {
        if ($file == "ToolTip.txt") {
			echo ("<h2>Tool Tip</h2><p class=\"tooltip\">");
			$file_contents = file($file);
			$array_items = sizeof($file_contents);
			$x = 0;
			while ($x < $array_items) {
				echo ("".$file_contents[$x]."<br />");
				$x++;
			}
			echo ("</p>");
        }
    }
    closedir($handle);
}
?>

i use this one its really cool its jquery.
its called jtip
ops but u save the tip as a htm file.

Can you do something similar to that php in asp or asp.net without having to have 2k worth of code?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.