Ignoring some scripts in <head> #175

Closed
opened 2018-09-08 22:48:28 -05:00 by nanook21 · 5 comments
nanook21 commented 2018-09-08 22:48:28 -05:00 (Migrated from github.com)

Hi,

Is there a way to set a selector on "head" but to prevent certain scripts from being re-run on a new page load?

Andrew

Hi, Is there a way to set a selector on "head" but to prevent certain scripts from being re-run on a new page load? Andrew
BehindTheMath commented 2018-09-08 22:52:32 -05:00 (Migrated from github.com)

Use a global variable to store whether the scripts were run already, then check that value in your scripts.

Use a global variable to store whether the scripts were run already, then check that value in your scripts.
nanook21 commented 2018-09-09 00:09:09 -05:00 (Migrated from github.com)

Unfortunately that won’t work in my setup as there are some CMS scripts
that I don’t have access to modify.

I was hoping that there might be a way to specify class IDs to ignore
within the head?

On Sat, Sep 8, 2018 at 9:52 PM BehindTheMath notifications@github.com
wrote:

Use a global variable to store whether the scripts were run already, then
check that value in your scripts.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/MoOx/pjax/issues/175#issuecomment-419688902, or mute
the thread
https://github.com/notifications/unsubscribe-auth/Ajr5sk3mqrLSip6WIvgWjdP6rgSd_c8Oks5uZJCBgaJpZM4WgIU4
.

Unfortunately that won’t work in my setup as there are some CMS scripts that I don’t have access to modify. I was hoping that there might be a way to specify class IDs to ignore within the head? On Sat, Sep 8, 2018 at 9:52 PM BehindTheMath <notifications@github.com> wrote: > Use a global variable to store whether the scripts were run already, then > check that value in your scripts. > > — > You are receiving this because you authored the thread. > Reply to this email directly, view it on GitHub > <https://github.com/MoOx/pjax/issues/175#issuecomment-419688902>, or mute > the thread > <https://github.com/notifications/unsubscribe-auth/Ajr5sk3mqrLSip6WIvgWjdP6rgSd_c8Oks5uZJCBgaJpZM4WgIU4> > . >
BehindTheMath commented 2018-09-09 08:37:25 -05:00 (Migrated from github.com)

There's no built in way to do that. Your bet bet is to move the script tag outside of any elements affected by Pjax.

There's no built in way to do that. Your bet bet is to move the script tag outside of any elements affected by Pjax.
nanook21 commented 2018-09-09 16:44:27 -05:00 (Migrated from github.com)

For others who might be interested, I was able to put together a workaround by adding this line of code below:

  loadContent: function(html, options) {
    // ADDED below line to strip items with the 'no-pjax' class name from the HTML:
    html = html.replace(/<.* class=(\'|\")no-pjax(\'|\")[^\0]*?\/.*>/g, '');
For others who might be interested, I was able to put together a workaround by adding this line of code below: ``` loadContent: function(html, options) { // ADDED below line to strip items with the 'no-pjax' class name from the HTML: html = html.replace(/<.* class=(\'|\")no-pjax(\'|\")[^\0]*?\/.*>/g, ''); ```
BehindTheMath commented 2018-09-11 21:07:48 -05:00 (Migrated from github.com)
[Re parsing HTML using regex](https://stackoverflow.com/a/1732454/8037425). 😄
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: iLoveElysia/pjax#175