pjax.js icon indicating copy to clipboard operation
pjax.js copied to clipboard

Run <script> in containers when pjax loaded

Open moeshin opened this issue 4 years ago • 2 comments

<body>
<script>alert('hi')</script>
</body>
Pjax.start({
    containers: ['body']
});

moeshin avatar Oct 10 '21 05:10 moeshin

like: https://github.com/MoOx/pjax/blob/480334b18253c721ba648675e90261f948e2bca0/lib/eval-script.js

moeshin avatar Oct 10 '21 05:10 moeshin

@moeshin Thanks for the helpful advice. When I created the library I thought of implementing this using documentgetElementsByTagNameScript, but at the time it seemed to me that it would be better to create an event to detect route changes, as in the example:

document.addEventListener("pjax:complete", function() {
  console.log("Event: pjax:complete", arguments);
});

I still intend to implement (it will be a feature that can be disabled). I will notify you shortly with the lib update.

brcontainer avatar Oct 12 '21 03:10 brcontainer