How to Disable JavaScript for One Passage?

I have the following code in Story-JavaScript which applies to all passages:

// (A) PREVENT CONTEXT MENU FROM OPENING
document.addEventListener(“contextmenu”, (evt) => {
evt.preventDefault();
}, false);

However, on one specific passage, I don’t want this script to be effective. How can I turn off JS for just one passage?

Thanks.

Twine Version: 2.4.1
Story Format: SugarCube

Could you remove the event listener and then re-add it when you need it again?

Could you please give an example of how to write it in a passage? I am not familiar with writing JS directly in a passage.

The passage I will be removing the JS effect is the last passage so I don’t need to add it back.
Thanks.

Sure! I’d be happy to help with that. (Full Disclaimer: I know nothing about Twine.)

From my understanding of the link to the docs, it looks like it’s just a simple copy-paste to disable that code for the context menu.

document.removeEventListener((“contextmenu”, (evt) => {
  evt.preventDefault();
}, false);

Then just a copy-paste to bring it back.

document.addEventListener(“contextmenu”, (evt) => {
  evt.preventDefault();
}, false);

Hopefully, this works for you. :slight_smile:

Just use an if statement.

document.addEventListener(“contextmenu”, (evt) => {
  if (passage() !== "name of passage") {
    evt.preventDefault();
  }
}, false);

note: If the purpose of that contextmenu event listener is to prevent the Readers from “cheating”, then (as it’s already been shown to you) that method is useless because it is so easily for them to bypass.

It works, thank you.