SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Trash Boat mkoenig's Avatar
    Join Date
    Aug 2007
    Posts
    1,232
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple Javascript Tooltip to show content of remote page.

    Can someone share some code on a simple javascript tooltip?

    I've used about everyone i've found online, with no success.

    The problem seems to be that these tooltips don't use the fully qualified domain to include pages just tip1.htm instead of somedomain.com/tip.htm

    Trying to create a "plugin" of script that people coming to the site can cut and paste into their own page and that code will show the content of my remote page.

    Anyone ever ran into this before? Any help is welcome.

  2. #2
    SitePoint Addict Zarin Denatrose's Avatar
    Join Date
    Jan 2009
    Location
    Surrey BC, Canada
    Posts
    309
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it's probably using just tip1.htm because it's using a file on the local site, likely generated by php.
    If you make an ajax request, passing the url you want to get as a variable to a PHP page and use file_get_contents($_REQUEST['url']), you can echo it in the response, send it back as text and send it to your tooltip plugin.

  3. #3
    Trash Boat mkoenig's Avatar
    Join Date
    Aug 2007
    Posts
    1,232
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Awesome, im awful at javascript but think this may "fix me"

    I really appreciate it

  4. #4
    SitePoint Addict Zarin Denatrose's Avatar
    Join Date
    Jan 2009
    Location
    Surrey BC, Canada
    Posts
    309
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No problem. The function I mentioned is a PHP function. You'll need to include it in a file with your scriptlet and have the javascript point to that file and wait for a response. I suggest using jquery if you're at all fuzzy on how this is done. Ajax is nice and simple using jQuery.

  5. #5
    Trash Boat mkoenig's Avatar
    Join Date
    Aug 2007
    Posts
    1,232
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Im decent at php bad a javascript. Those other tooltips where using jquery.

    so i guess i just need to sit down and understand the jquery library right?

  6. #6
    SitePoint Addict Zarin Denatrose's Avatar
    Join Date
    Jan 2009
    Location
    Surrey BC, Canada
    Posts
    309
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, but it's really a lot simpler than raw javascript.
    Say you wanted the tooltip on a link with a class of tooltip:
    Code:
    $("a.tooltip").hover( 
    function() {
    //Mouse Over
    $.post(
    "tooltip.php",
    {//Data goes here, but it won't be needed.}, 
    function($response){$("#tooltipBox").html($response).show("fast")},
    type
    );
    },
    function(){
    //Mouse Out
    $("#tooltipBox").hide("fast");
    }
    );
    There's more that can be done in terms of optimizing this, and this by no means constitutes a full tooltip, but it does show #tooltipBox when you hover over the link, after injecting the code from your page into it and hide it when you mouse away.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •