Home > Mobile >  Open a modal window while click on an anchor tag in a mail content
Open a modal window while click on an anchor tag in a mail content

Time:03-02

In my application I am sending a mail content with a link that is anchor tag. While click on that link from mail user has to redirect to the website and need to show a popup. How can I do that?we have to open corresponding comment box popup while click on that link

$subject = "New Task Created";
    
                $message = '
                <html>
                
                <body>
                
                <table>
                <tr>
                    <td>content.</td>
                </tr>
                
                <tr><td><a  href="#"   data-toggle="modal" data-target="#exampleModalLong'.$lastid.'">Comment</a></td></tr>

                </table>
                </body>
                </html>
                ';
    $to='[email protected]';
                // Always set content-type when sending HTML email
                $headers  = 'MIME-Version: 1.0' . "\r\n";
               $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
                    $headers .= 'From: test <[email protected]>' . "\r\n";
                    
                    // send email
                    mail($to, $subject, $message, $headers);

CodePudding user response:

The code to open the modal automatically must be executed in the destination page.

So your link should be open your page, and pass an extra parameter to say to that page to open the modal.

For example:

<a href="https://yourdomain.com/page-where-the-modal-is-located#exampleModalLong'.$lastid.'">

Then, within your page, you need to read that parameter and open the modal in Javascript. Based on the HTML data attributed you use, I assume you're using bootstrap. So the following code should work.

$( document ).ready(function() {
    if(window.location.hash.indexOf('exampleModalLong') != -1) {
        $(window.location.hash).modal('show');
    }
})
  • Related