0

I'm using the following code:

<center>Supporto Live Chat<br>
  <a onclick="window.open('https://google.com/','Live Chat','scrollbars=yes,width=500,height=715');return false;" href="https://google.com"><img class="wp-image-1182 aligncenter" alt="live-butt" src="https://cdn.pixabay.com/photo/2016/06/06/16/39/phone-1439839_960_720.png" width="142" height="75" /></a>
</center>
<hr>

This can be tested here: https://htmledit.squarefree.com/

But I have the issue that the pop up opened is not centered. Any suggestion on how the code can be edited to have the pop up centered?

Thank you

  • 1
    Don't use the [`center` element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/center). There are [many other ways to center an element](https://developer.mozilla.org/en-US/docs/Web/CSS/Layout_cookbook/Center_an_element) – evolutionxbox Jan 28 '22 at 09:46

2 Answers2

1

Go to this for reference : https://www.geeksforgeeks.org/how-to-center-a-popup-window-on-screen/#:~:text=This%20example%20creates%20the%20pop%20up%20window%20and%20placing%20it%20into%20center

<center>Supporto Live Chat<br>
  <a onclick="window.open('https://google.com/','Live Chat','scrollbars=yes,width=500,height=715');return false;" href="https://google.com"><img class="wp-image-1182 aligncenter" alt="live-butt" src="https://cdn.pixabay.com/photo/2016/06/06/16/39/phone-1439839_960_720.png" width="142" height="75" /></a>
</center>
<hr>
   <script>
    function createPopupWin(pageURL, pageTitle,
                popupWinWidth, popupWinHeight) {
        var left = (screen.width - popupWinWidth) / 2;
        var top = (screen.height - popupWinHeight) / 4;
          
        var myWindow = window.open(pageURL, pageTitle, 
                'resizable=yes, width=' + popupWinWidth
                + ', height=' + popupWinHeight + ', top='
                + top + ', left=' + left);
    }
</script>
  
Nitin Shinde
  • 136
  • 9
-1

How about a javascript to help you, The javacsript calculates the center of the screen and palces the window there.

       <!DOCTYPE html>
<html>
   <body>
      <script>
         function myPopup(myURL, title, myWidth, myHeight) {
            var left = (screen.width - myWidth) / 2;
            var top = (screen.height - myHeight) / 4;
            var myWindow = window.open(myURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=' + myWidth + ', height=' + myHeight + ', top=' + top + ', left=' + left);
         }
      </script>
<center>Supporto Live Chat<br>      
        <a onclick=" myPopup ('https://google.com/','Live Chat', 500, 715);"><img 
        class="wp-image-1182 aligncenter" alt="live-butt" 
        src="https://cdn.pixabay.com/photo/2016/06/06/16/39/phone-1439839_960_720.png" 
        width="142" height="75" /></a>
      </center>
   </body>
</html>
Hasse
  • 227
  • 3
  • 7
  • The example is invalid. Please may you fix the errors? And may you also add a description as to what you did. – evolutionxbox Jan 28 '22 at 10:12
  • My intial example of code works on https://htmledit.squarefree.com/ I tested on the same website the solution gived here but is not working for me. My code works if pasted in that real time html editor. The solution provide here seems is not working for me, the button doesn't open a pop up. – user17389456 Jan 28 '22 at 10:18
  • Strange, something happend then I pasted the code here. Anyway it should be working now, try again. – Hasse Jan 28 '22 at 10:28
  • Now works, thanks! I added just a CSS to show pointer as hand. Thank you! – user17389456 Jan 28 '22 at 10:34
  • Hasse the downvote is not mine. You helped a lot! I cannot vote, I can just select your answer as the best and I do. Also my question was closed by someone point to a topic that was not helpful for me. This is something not really nice. – user17389456 Jan 28 '22 at 10:39