Forum Discussion

RonLinder-4c1a3's avatar
RonLinder-4c1a3
Community Member
2 months ago

Closing module mechanism

Is there a way to do the following:

If a user closes the module at any time using the "X" of the window --> redirect to another URL.

Also I have a jscript inside my storyline that stores the userID, is there a way to have that as a parameter in that URL that I am redirecting?

 

 

  • Hi RonLinder-4c1a3 if you are saying the "x" on the browser window, I don't think you can then stop that action and re-direct to another URL. If you are suggesting that they close "x" on browser Window 1, which then re-directs browser window 2, this should be possible using JavaScript "onbeforeunload" event listener in Window 1.

    Note: Window 2 would also need to be controlled by Window 1 in this instance (for example launched by it), in order for it to allow any script in Window 2 to affect it.

    It would also be possible to get the userID and use it as a parameter in the URL:

    const player = GetPlayer();
    const userID = player.GetVar("userID");
    const url = `https://abc.com.au?userID=${userID}`;
    // You'd need to adjust this for the browser window you are targeting
    document.location = url;

     

    • RonLinder-4c1a3's avatar
      RonLinder-4c1a3
      Community Member

      I managed to do it this way which is similar to your suggestion:

      // Get the value of the Storyline variable
      let player = GetPlayer();
      player.SetVar("Exit_Course",true);
      var empID = player.GetVar("student_id");
      var url = "https://xxxx.com/index.aspx?csf=1&web=1&e=eDNr93&EmployeeID=" + empID;  
      var win = window.open(url);

      But the issue I am having is Workday does the following when someone navigates to a module:

      1. opens a tab in browser
      2. when you click to open the module it opens a popup window with the module in it
      3. how do I close that initial tab (in step 1) when the popup window is closed?

      I tried:

      var win window.top.close();

      but nothing happens.

      Also tried:

      EXIT_BEHAVIOR = "ALWAYS_CLOSE_PARENT";  

      But no go as well.

      • SamHill's avatar
        SamHill
        Super Hero
        window.opener.close()

        You can reference the browser window that opened the one you are in through JavaScript window.opener. it is possible it will not allow it to close though.

         

  • I doubt you can close the parent because you didn't open it programmatically

    • RonLinder-4c1a3's avatar
      RonLinder-4c1a3
      Community Member

      Yes correct, from my research and trial and error there is no way of closing that initial page. That page is also not from the storyline folder but from workday from my understanding. 

      It is a page workday generated that redirects the user to the storyline file called index_lms.html

      So I tried to JScript a close within this "index_lms.html" file to close that parent/top file that workday created but it never works.

      In summary, I gave up :)