Forum Discussion

Jonathan_Gibson's avatar
Jonathan_Gibson
Qrew Cadet
4 months ago

OpenAsPopup position

I am utilizing the OpenAsPopup class to open a small form as a popup window when a user clicks a button. Is there an attribute for OpenAsPopup (or any other technique for that matter) that will enable me to control the position of the popup window?

Ideally the window should appear close to where the button was clicked. Barring this the middle of the screen would be preferable to the default, top-left position.

1 Reply

  • Hi Jonathan,

    The standard OpenAsPopup class doesn't have built-in attributes for positioning, but you can control the popup position using JavaScript with the window.open() method instead if you're using a code page. I don't think any of this accepted in formula fields though.

    Here's an approach that gives you more control within a code page:

    Instead of relying solely on the OpenAsPopup class, use a custom JavaScript function in your rich text formula:

    ```javascript

    "<a href='javascript:void(0)' onclick=\\"

    var width = 850;

    var height = 600;

    var left = (screen.width/2)-(width/2);

    var top = (screen.height/2)-(height/2);

    window.open('" & [Your URL Field] & "', 'popupWindow', 'width='+width+',height='+height+',top='+top+',left='+left+',resizable=yes,scrollbars=yes');

    return false;

    \\">Click Here</a>"

    ```

    This centers the popup on screen. If you want it to appear near where the user clicked, you can capture the click event coordinates, but that gets more complex.

    Hope this helps!