URL Resource pop-up also opens new tab/window

Issue #94 closed
Jeremy FitzPatrick created an issue

Pre-requisite

Allow popups for the site

Steps

Add a URL resource to the course page (any tile)

Choose “In pop-up” for Display, in the Appearance section

View page with Editing off or as Student

Click the URL link

Expected

A popup window opens with the requested URL

Actual

A popup window opens with the requested URL

And a new tab or browser window opens with the URL

Comments (9)

  1. tmw

    I’m experiencing a similar problem as well using Moodle 4.0.2 with Tiles plugin version 4.0.0.2 Beta/2022070200, as far as I can tell this isn’t being caused by custom code elsewhere in our Moodle. When I click on the PDF File resource, the PDF opens in both a modal dialogue and a new browser window.

    Steps to reproduce:

    • Ensure the PDF option is ticked in the plugin settings Modal resources option.
    • Create a file resource linked to a PDF and set the Appearance>Display to “In pop-up”.
    • Save and click on the file resource.

    The Moodle 4.0.2 installation is a test site, our live Moodle 3.9.14 site with Tiles version 3.11.1.3/2020080629 does not exhibit this problem.

    Additional: The New Window display option also triggers this problem, with both the browser tab and dialogue being opened. Again, this problem is not apparent in Moodle 3.9.14.

  2. tmw

    I’ve found a further variation of this issue, if I set up a URL resource using the “New Window” option, the link will either open two new tabs, or trigger the “popups blocked” message while still opening a single tab.

  3. tmw

    The problem here seems to be that the standard Moodle libraries are adding an onclick attribute to the anchor tag, Tiles then adds a second event listener via it’s AMD module. The event listener in the attribute fires first, so the call to preventDefault() on the event in the Tiles AMD module doesn’t prevent the double opening. I’ve got a workable fix for this (which may or may not be the “best” solution) that involved overriding the renderable object for the title and removing the onclick attribute if it isn’t needed. The attached title.php file needs to be dropped into course/format/tiles/classes/output/courseformat/content/cm/ to implement the fix.

    This hasn’t been extensively tested, it’s likely to be 2023 before our live site gets upgraded to Moodle 4+.

  4. Andreas Siebel

    In addition to this issue: If you open a resource in a new window, a popup opens at the same time. If you jump back by closing the window, the popup remains open.

  5. David Watson repo owner

    A fix for this is in the 4.3.0.8 BETA release which will be on moodle.org later. Apologies for not getting to this sooner.

    @tmw thanks for the proposed fix. I adopted a slightly different approach in order to simplify my code which was over complicated. If the activity is set to “pop up” then only the core pop up will be generated. The Tiles modal will be suppressed.

  6. Log in to comment