I need to open a popup on click of anchor link. I followed this (How to open popup when <a> tag onClick?) answer but the issue is that i have to add script inside .phtml file.

I want to include the script in .js file and then use it. How can i achieve this?

I have already tried by adding inside Vendor/Theme/web/js/custom.js but then the pop up is not getting displayed.

The second solution in the (How to open popup when <a> tag onClick?) link is not working for me.

Can some guide me towards this?

  • i hope you have checked my answer Commented Feb 15, 2019 at 11:01

1 Answer 1


Please add the following to show popup:

<div class="view-popup"  onclick="show_popup()">
    <span>click to view popup</span>

whatever you want to show in popup,

<div id="popup-wrapper" style="display:none;" >
    <div class="popup-content">
        popup content popup content

Add below popup script:

<script type="text/javascript">

    ], function ($, confirm, storage) {
        window.show_popup = function () {
            var options1 = {
                type: 'popup',
                responsive: true,
                clickableOverlay: false,
                title: 'Size Chart',
                buttons: [{


You can use Anchor tag instead of span.

clear the cache and check..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.