Programming_Sloth
Programming_Sloth

Reputation: 1

PHPStorm - change the position of a pop-up window to open on another monitor

I'm new to programming and I have got a problem with the pop-up window of my website.

There is a button that opens a pop-up window, and in the process, it generates a pdf-file in the new opened window. The problem that I have is, that the pop-up window does not stay on the other screen. I'm working with a dual monitor setup and the pop-up always appears on the screen, where the main browser is opened on.

If the main browser tab is opened on the left screen, I want the pop-up to always show on the right side on the position, where I dragged it to and vice versa. I just can't get it to work propperly and I have high hopes, that someone here could help me out with this problem.

Thanks in advance and have a great day!

I tried to add values to the window screen width and the screen top. I asked ChatGPT about the problem but could not get a working answer, even with providing my code.

EDIT: The code looks like this:

<iframe src="pdf-file-location.pdf" width="100%" height="100%"></iframe>
<script>
    var windowName = "pdfWindow1234";

    function savePosition() {
        var position = {
            left: window.screenX,
            top: window.screenY
        };
        localStorage.setItem(windowName, JSON.stringify(position));
    }

    window.onbeforeunload = savePosition;

    window.onload = function() {
        var defaultPosition = { left: 100, top: 100 };
        var savedPosition = JSON.parse(localStorage.getItem(windowName)) || defaultPosition;
        window.moveTo(savedPosition.left, savedPosition.top);
    };

and:

<button onclick="openPdfWindow()">open pdf</button>
<script>
    function openPdfWindow() {
        var windowName = "pdfWindow1234";
        var windowFeatures = "width=800,height=600";
        var pdfUrl = "pdf.txt"; 

        var defaultPosition = { left: 100, top: 100 };
        var savedPosition = JSON.parse(localStorage.getItem(windowName)) || defaultPosition;

        windowFeatures += `,left=${savedPosition.left},top=${savedPosition.top}`;
        
        var newWindow = window.open(pdfUrl, windowName, windowFeatures);

        if (!newWindow) {
            alert("Pop-up blocker is enabled! Please allow pop-ups for this website.");
        }
    }

Upvotes: 0

Views: 83

Answers (0)

Related Questions