0

I'm using Fullcalendar for a project, and when I've event click with URL, it opens it on new tab. I would like it redirect just the user, on the same page.

In my code, I use :

        eventClick: function(event) {
            if (event.url) {
                window.open(event.url, "_self");
                return false;
            }
        },

But it doesn't work

I removed this function. However, I use a listener to get my events from the database, in PHP.

For my events, I set the 'url' option like this :

$absenceEvent->addOption(
                    'url',
                    $this->router->generate('absences_prevision_edit', [
                        'id' => $absence->getId(),
                    ])
                );

It works, but it opens a new tab too, I just want a "redirection"

eronn
  • 1,690
  • 3
  • 21
  • 53
  • You can just remove that entire code then. As the [documentation](https://fullcalendar.io/docs/event-object) mentions, fullCalendar will automatically handle clicks on an event which has a URL property, and automatically navigate the browser to that new URL – ADyson Nov 25 '19 at 21:39
  • P.S. If you _did_ need to do this task using your own code inside the eventClick, you would simply use window.location instead of window.open. https://stackoverflow.com/questions/503093/how-do-i-redirect-to-another-webpage – ADyson Nov 25 '19 at 21:41

1 Answers1

0

You should add a method that prevents the browser from following links in the current tab. This is the code I used and it's working well.

eventClick: function(info) {
    if (info.event.url) {
        window.open(info.event.url);
        info.jsEvent.preventDefault();
    }
}
Imran Rafiq Rather
  • 7,677
  • 1
  • 16
  • 35