Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6926793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:57:52+00:00 2026-05-27T10:57:52+00:00

I started writing a Greasemonkey script as a start for learning JavaScript. What the

  • 0

I started writing a Greasemonkey script as a start for learning JavaScript. What the script does is simply when you hover your mouse pointer over a thumbnail image, if enlarges that picture to a popup window.

And I’m almost done. But there’s a few snags…

  1. when the mouseenter event fires, it spawns a popup and it also loads that same image in the webpage itself! Thus preventing it from executing the mouseleave part too, I think.

  2. How do I set the width and the height of the popup dynamically according to the particular measurements of the loading image?

  3. In the ‘/thumbs/75×60/’ part, I want to use the * wildcard to replace ’75×60′ (as in * x * ) so that any size of thumbnail pic would be affected. How do I do that?

See http://jsfiddle.net/JWcB7/6/

The HTML is like:

<div id="profPhotos">
    <a class="profPhotoLink" href="...">
        <img width="95" height="130" src=".../thumbs/163x130/8f/fd/588x800_1319044306_9223981.jpg">
    </a>
    <br>
    <a class="profPhotoLink" href="...">
        <img width="75" height="60" src=".../thumbs/75x60/f0/d9/604x453_1319044306_9254715.jpg">
    </a>
    ... ...
</div>

The JS is:

$('#profPhotos .profPhotoLink > img').bind
(
    "mouseenter mouseleave", myImageHover
);

function myImageHover (zEvent)
{
    if (zEvent.type == 'mouseenter')
    {
        var imgurl = this.src.toString();
        //need to replace '/thumbs/75x60/' part with '/photos/' to get the full size image
        var bigimg = imgurl.replace("/thumbs/75x60/", "/photos/");  
        window.location.href = bigimg;
        popup = window.open(bigimg,"popwindow","menubar=0,resizable=0,status=0,titlebar=0,toolbar=0,scrollbars=0,location=0,width=600,height=800") //how to set the width and the height dynamically
    }
    else
    {
        popup.close();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:57:53+00:00Added an answer on May 27, 2026 at 10:57 am

    If you don’t want the image to load in the same page as well don’t do this! :

    window.location.href = bigimg;
    

    Or did you want the image there somehow as well as the popup?

    ~~~
    As for the wildcard replace, that’s easy. Change:

    var bigimg = imgurl.replace("/thumbs/75x60/", "/photos/");
    

    To:

    var bigimg = imgurl.replace(/\/thumbs\/[0-9x]+\//i, "/photos/");  
    

    ~~~
    Resizing the popup gets tricky Do you really want a popup on mouseover!!? Would a flyover larger image do?

    I do not recommend using an actual popup (window.open()) to show the large images. Because of security blocking and cross-site restrictions, this can be a right pain. But it’s possible with Greasemonkey.

    Instead, I recommend you show the image in a pseudo-popup dialog. Do this by inserting a <div> that’s position: absolute; and has a high z-index.

    The mouseenter event would then change the src of the image inside the div.

    Putting it all together, here is a complete Greasemonkey script that generates simple popup images on mouseover:

    You can see the code in action at jsBin.

    // ==UserScript==
    // @name    _Popup Image Flyover, Mark I
    // @include http://YOUR_SERVER/YOUR_PATH/*
    // @require http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js
    // ==/UserScript==
    
    /*--- Create the div and the image that will be pointed to our large
        pictures.
    */
    $("body").append ('<div id="idLargePicturePopupWindow"><img></div>');
    
    /*--- In case the popup covers the current mouse position, it must also
        trigger the hover change.  This avoids certain annoying blinking
        scenarios.
    */
    $('#idLargePicturePopupWindow').bind (
        "mouseenter mouseleave",
        {bInPopup: true},
        myImageHover
    );
    
    /*--- Activate the mouseover on the desired images on the target page.
    */
    $('#profPhotos .profPhotoLink > img').bind (
        "mouseenter mouseleave",
        {bInPopup: false},
        myImageHover
    );
    
    function myImageHover (zEvent) {
        if (zEvent.type == 'mouseenter') {
    
            if ( ! zEvent.data.bInPopup) {
    
                var imgurl = this.src.toString();
                /*--- Need to replace '/thumbs/75x60/' part with '/photos/'
                    to get the full size image.
                */
                var bigimg = imgurl.replace(/\/thumbs\/[0-9x]+\//i, "/photos/");
    
                $("#idLargePicturePopupWindow img").attr ('src', bigimg);
            }
    
            $("#idLargePicturePopupWindow").show ();
        }
        else {
            $("#idLargePicturePopupWindow").hide ();
        }
    }
    
    
    /*--- Here we add the CSS styles that make this approach work.
    */
    GM_addStyle ( (<><![CDATA[
        #idLargePicturePopupWindow {
            position:               absolute;
            background:             white;
            border:                 3px double blue;
            margin:                 1ex;
            opacity:                1.0;
            z-index:                1222;
            min-height:             100px;
            min-width:              200px;
            padding:                0;
            display:                none;
            top:                    10em;
            left:                   10em;
        }
        #idLargePicturePopupWindow img {
            margin:                 0;
            margin-bottom:          -4px;
            padding:                0;
        }
    ]]></>).toString () );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just started writing my own JavaScript Framework (just for the learning experience),
I started writing some JS code to cause a variables value to increase over
Got an issue, and need your advices I just started writing an editor grid.
I've started writing a lot more javascript lately and am trying to do it
I started writing functional tests for my rails app today. I use the RESTful
When I started writing database queries I didn't know the JOIN keyword yet and
I've started writing a few applications in PHP, and I'm becoming more familiar with
I have started writing a Macro in Visual Studio 2005 like this: Public Sub
What are some resources for getting started writing a Firefox Addon? Is there an
In my free time I started writing a small multiplayer game with a database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.