SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jan 2009
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript Pop Up Centered

    Hi everyone - a quick, and probably easy question:

    I am implementing a pop up window and need it to be centered. Found this code (below) seems to work good. I need to open it with an image rather than text link. Can anyone provide the correct syntax for this, if say the image was called 'test.jpg'? Thanks!

    - - - - - - - - - - -

    <script type="text/javascript">
    <!--
    function popup(url)
    {
    var width = 300;
    var height = 200;
    var left = (screen.width - width)/2;
    var top = (screen.height - height)/2;
    var params = 'width='+width+', height='+height;
    params += ', top='+top+', left='+left;
    params += ', directories=no';
    params += ', location=no';
    params += ', menubar=no';
    params += ', resizable=no';
    params += ', scrollbars=no';
    params += ', status=no';
    params += ', toolbar=no';
    newwin=window.open(url,'windowname5', params);
    if (window.focus) {newwin.focus()}
    return false;
    }
    // -->
    </script>

    <a href="javascript: void(0)"
    onclick="popup('popup.html')">Centered popup window</a>

  2. #2
    SitePoint Enthusiast David.A's Avatar
    Join Date
    May 2010
    Location
    Milky Way Galaxy
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just put the image in rather the the text.

    Code:
    <a href="javascript: void(0)" onclick="popup('popup.html')">
    <img src="test.jpg" alt="" /></a>

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A better way to approach this would be the following:

    Code:
    <a href="images/myImage.jpg" onclick="popup(this.href)">Open my image</a>
    Good luck

  4. #4
    SitePoint Enthusiast David.A's Avatar
    Join Date
    May 2010
    Location
    Milky Way Galaxy
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SlickAU, Range isn't looking to open an image, but rather,
    open it with an image rather than text link.
    Your solution just opens an image, it doesn't replace the text with an image.


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
  •