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

  • Home
  • SEARCH
  • 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 7912821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:42:01+00:00 2026-06-03T13:42:01+00:00

Hi, I have done a popup which is by default hidden and opened whenever

  • 0

Hi,

I have done a popup which is by default hidden and opened whenever a click is triggered on window. Popup must be shown at wherever the event is triggered.But there are some constraints:

  1. Popup must be shown at current visible window.Meaning,If I clicked at right most part of the window then,popup must be shown to right side of the clicked position to avoid scrolling.

  2. If window has scrolling, irrespective of scrolling it should be shown at visible part of the window.

Everything is working fine in my present code except in the case,if window has scrolling.
If scroll down and click on the middle of the window, popup is displayed at out of the window current display area…………………….

<!DOCTYPE HTML PUBLIC>
<html>
 <head>
  <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.js"></script>
  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.js"></script>
 <style>
   div{
     border:1px solid;
     background:#ff9999;
     width:500px;
     height:500px;
     display:none;
     position:absolute;
   }
 </style>
  <script>
   var mouseX,mouseY,windowWidth,windowHeight;
   var  popupLeft,popupTop;
 $(document).ready(function(){

   $(document).mousemove(function(e){
           mouseX = e.pageX;
           mouseY = e.pageY;
           //To Get the relative position
           if( this.offsetLeft !=undefined)
             mouseX = e.pageX - this.offsetLeft;
           if( this.offsetTop != undefined)
             mouseY = e.pageY; - this.offsetTop;

           if(mouseX < 0)
                mouseX =0;
           if(mouseY < 0)
               mouseY = 0;

           windowWidth  = $(window).width();
           windowHeight = $(window).height();
   });

     $('html').click(function(){
       $('div').show();
      var popupWidth  = $('div').outerWidth();
      var popupHeight =  $('div').outerHeight();

      if(mouseX+popupWidth > windowWidth)
        popupLeft = mouseX-popupWidth;
      else
       popupLeft = mouseX;

      if(mouseY+popupHeight > windowHeight)
        popupTop = mouseY-popupHeight;
      else
        popupTop = mouseY; 
      if(popupLeft < 0)
          popupLeft = 0;
      if(popupTop < 0)
          popupTop = 0;

      $('div').offset({top:popupTop,left:popupLeft});
     });
 });
  </script>
 </head>

 <body>
        <br/><br/><br/>  <br/><br/><br/><br/> <br/><br/> <br/>   <br/>   <br/>   <br/>   <br/>   <br/> 
        <br/><br/> <br/> <br/> <br/>    <br/><br/><br/> <br/><br/>  <br/>   <br/><br/><br/><br/><br/><br/>
        <br/><br/><br/><br/><br/><br/><br/><br/>    

        <div>
         s dflasld fsadf
         sdfas dfsadf
        </div>

</body>

</html>

Can you please check it…….

  • 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-06-03T13:42:02+00:00Added an answer on June 3, 2026 at 1:42 pm

    Finally, I could done it by having small changes…This is the piece of code that works fine…

    <html>
     <head>
      <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.js"></script>
      <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.js"></script>
     <style>
       div{
         border:1px solid;
         background:#ff9999;
         width:500px;
         height:500px;
         display:none;
         position:absolute;
       }
     </style>
      <script>
       var mouseX,mouseY,windowWidth,windowHeight;
       var  popupLeft,popupTop;
     $(document).ready(function(){
    
       $(document).mousemove(function(e){
               mouseX = e.pageX;
               mouseY = e.pageY;
               //To Get the relative position
               if( this.offsetLeft !=undefined)
                 mouseX = e.pageX - this.offsetLeft;
               if( this.offsetTop != undefined)
                 mouseY = e.pageY; - this.offsetTop;
    
               if(mouseX < 0)
                    mouseX =0;
               if(mouseY < 0)
                   mouseY = 0;
    
               windowWidth  = $(window).width()+$(window).scrollLeft();
               windowHeight = $(window).height()+$(window).scrollTop();
       });
    
         $('html').click(function(){
           $('div').show();
          var popupWidth  = $('div').outerWidth();
          var popupHeight =  $('div').outerHeight();
    
          if(mouseX+popupWidth > windowWidth)
            popupLeft = mouseX-popupWidth;
          else
           popupLeft = mouseX;
    
          if(mouseY+popupHeight > windowHeight)
            popupTop = mouseY-popupHeight;
          else
            popupTop = mouseY; 
    
        if( popupLeft < $(window).scrollLeft()){
         popupLeft = $(window).scrollLeft();
        }
    
        if( popupTop < $(window).scrollTop()){
         popupTop = $(window).scrollTop();
        }
    
         if(popupLeft < 0 || popupLeft == undefined)
               popupLeft = 0;
          if(popupTop < 0 || popupTop == undefined)
               popupTop = 0;
    
          $('div').offset({top:popupTop,left:popupLeft});
         });
     });
      </script>
     </head>
    
     <body>
            <br/><br/><br/>  <br/><br/><br/><br/> <br/><br/> <br/>   <br/>   <br/>   <br/>   <br/>   <br/> 
            <br/><br/> <br/> <br/> <br/>    <br/><br/><br/> <br/><br/>  <br/>   <br/><br/><br/><br/><br/><br/>
            <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>        
    
            <div>
             s dflasld fsadf
             sdfas dfsadf
            </div>
    
    </body>
    
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a popup window from which I want to retrieve a value, I
I have a page which spawns a popup browser window. I have a JavaScript
I have a div section in which I have an image whose onclick event
I have an aspx.cs page with the following code: hypPopup.Attributes.Add(onclick, window.open('Popup.aspx', '', 'height=650, width=800,
I have a popup which upon hoover requests data from the server to display.
Have done some research and found some stuff that may be helpful. I would
I have done XML parsing before but never on a massive scale. If I'm
I have done some research, and majority of the examples I have found use
I have done this operation millions of times, just using the + operator! I
I Have done a site but want to redirect it to another subdomain in

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.