Skip to main content
stacyr7919679
Participant
November 23, 2015
Question

Captivate 8: JavaScript popup window

  • November 23, 2015
  • 2 replies
  • 1064 views

Hello!

I use the Execute JavaScript function in Captivate 8 and it works very well.  I want to modify this, though, for a project so that the popup opens in the center of the page.  Does anyone have experience with this or have any suggestions?  Here is the code I use in the script_window:

var win = window.open('url', 'popup', 'width=800, height=800, location=no, menubar=no, status=no, toolbar=no, scrollbars=no, resizable=no');

win.focus();


Thank you all in advance!

    This topic has been closed for replies.

    2 replies

    TLCMediaDesign
    Inspiring
    November 23, 2015

        var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : screen.left;
        var dualScreenTop = window.screenTop != undefined ? window.screenTop : screen.top;

        width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
        height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;

        var left = ((width / 2) - (w / 2)) + dualScreenLeft;
        var top = ((height / 2) - (h / 2)) + dualScreenTop;
        var newWindow = window.open(url, title, 'scrollbars=yes, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);

       
        if (window.focus) {
            newWindow.focus();
        }

    RodWard
    Community Expert
    Community Expert
    November 23, 2015

    Ahh.  I forgot we have a JavaScript guru in the house!

    Participant
    November 23, 2015

    A suggestion; is using Web Object an option in your project?

    stacyr7919679
    Participant
    November 23, 2015

    Thank you! That is a great idea, however, I want the object to open up in the center and the web object opens in the top left.  Is there a way to add that function into the web object? 

    Participant
    November 23, 2015

    In regards of web object on the top left, you can simply position your web object on the top left but hidden.

    Next, you could create an Advanced Action.

    First line, execute the script to show pop up

    Send line, tell Captivate to show the hidden web object.

    Next step, attach the Advanced action to a button. Now, when this button is pressed, a popup will appear and a web object will be visible on the top left.