I used the plug-in for image viewing, In the plug-in, the window resize event is added. When I switch several pages, I find that the resize event has been added repeatedly.
After clicking to switch the page several times, the event is added repeatedly
I used the plug-in for image viewing, In the plug-in, the window `resize` event is added. When I switch several pages, I find that the `resize` event has been added repeatedly.
#### Make a demo
>example.js
```javascript
function event(){
document.addEventListener('resize',function (){
console.log('add event');
})
}
document.addEventListener("pjax:success", function() {
console.log("Event: pjax:success", arguments);
// Init page content
initButtons();
event();
});
document.addEventListener("DOMContentLoaded", function() {
// Init Pjax instance
pjax = new Pjax({
elements: [".js-Pjax"],
selectors: [".body", "title"],
cacheBust: true
});
console.log("Pjax initialized.", pjax);
// Init page content
initButtons();
event();
});
```
After clicking to switch the page several times, the event is added repeatedly

This is because your "pjax:success" event listener calls your event function that adds a "resize" listener, meaning that every time you load a new page with Pjax, you add a new listener.
You should either only call this function once, or remove any previously-added "resize" listeners before adding a new one.
This is because your `"pjax:success"` event listener calls your `event` function that adds a `"resize"` listener, meaning that every time you load a new page with Pjax, you add a new listener.
You should either only call this function once, or remove any previously-added `"resize"` listeners before adding a new one.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
I used the plug-in for image viewing, In the plug-in, the window
resizeevent is added. When I switch several pages, I find that theresizeevent has been added repeatedly.Make a demo
After clicking to switch the page several times, the event is added repeatedly
This is because your
"pjax:success"event listener calls youreventfunction that adds a"resize"listener, meaning that every time you load a new page with Pjax, you add a new listener.You should either only call this function once, or remove any previously-added
"resize"listeners before adding a new one.