brcontainer / pjax.js

Turn any website into a PJAX website.
MIT License
27 stars 3 forks source link

Run <script> in containers when pjax loaded #4

Open moeshin opened 3 years ago

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

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

brcontainer commented 3 years ago

@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.