views:

82

answers:

2

I am trying to accomplish something very simple, and I'm hoping someone can point me in the right direction in the form of a javascript library that will do most of the work for me.

When the user mouseovers certain links on a page, I want the content of the target URL of the link to load as a "tooltip" style subwindow at the mouse cursor.

An example of very similar functionality can be found on this page if you mouseover one of the item names under "Guild Website Hosting Packages."

The biggest caveat is that I cannot control the output or formatting of the pages that will be loaded inline (they are not under my control) otherwise I would serve up JSON and do it "correctly."

A: 

Use AJAX to fetch the data, then:

var iframe = document.createElement('iframe');
iframe.innerHTML = ajax_response_html;

Then use your favourite JavaScript library to position the iframe to the coordinates available through the mouseover event object's properties, and style the iframe to be of a fixed, smaller size.

Kev
I was hoping to find a library or plugin to jQuery or something that would do exactly what you're talking about for me, but I will accept this if no one can provide one.
OverloadUT
+2  A: 

Use this jQuery tooltip plugin.

It's easy to configure, and it doesn't require AJAX, iFrames, or any other convoluted silliness.

Stefan Kendall
I believe my original question may have been unclear. I need the actual content of the target page to load as a "tooltip" style subwindow, not just the actual url text.
OverloadUT
From the plugin docs: "To display any customized content in the tooltip, provide the bodyHandler callback. Its return value will be inserted into the tooltip..." I don't know if the callback can stall while it fetches the content, though...I've had problems with synchronous AJAX before.
Kev
You don't have to use AJAX. You can pull hidden content from the DOM and the like to populate the tooltip. All html is valid, so you can go crazy.
Stefan Kendall
@OverloadUT: Kev is right. Look at the demos and documentation again.
Stefan Kendall
Okay, I'll look more closely. Note that I already mentioned that I must pull the content from the target URL, so hiding the content in the DOM is not an option. I do not control the target webpage, and it could be anything.
OverloadUT
I accepted your answer because it's the closest to what I asked for, however I have discovered that what I wanted to do is impossible anyway because the target URL is on a different host.
OverloadUT
Not quite impossible. You can hit a web service on YOUR server that pulls the content from another server. You have to use your server as the middle-man in the operation, and it's more involved, but it's not impossible.
Stefan Kendall
Ah, yes. I meant impossible using Javascript only. This whole thing was a passing fancy to implement a quick feature on a phpbb board, and having to write a whole webservice to do the work is outside the scope of what I was willing to do. :)But still good advice!
OverloadUT