Rich-text Reply

How to remove JavaScript from a test page?

envisionitmedia 04-18-14

How to remove JavaScript from a test page?

[ Edited ]

Is there a way to add a code to the variation code box that will block or remove a call to a JavaScript snippet that's loaded externally. For instance, I have a site where there's a jQuery script that makes a homepage banner rotate. It's called from the <head> of the page, and I would like to block it on certain variations.

 

I found a workaround which involved applying custom CSS to change the elements that the jQuery was affecting, but it would be easier to just remove the script from the variation.

kylerush 04-20-14
 

Re: How to remove JavaScript from a test page?

Removing script tags from the head is hacky and I would recommend finding other solutions. However, if the Optimizely snippet is loaded in the head before the script tag that you want to remove, you can try to remove it with DOM manipulation. Using a jQuery attribute selector you can try something like:

jQuery('script[src="SRC_OF_SCRIPT_TAG"]').remove();

More on jQuery's attribute selector here: https://api.jquery.com/attribute-equals-selector/

I've never tried this before so be sure to QA it before trying it in production.
Optimizely
db-_-db 05-16-14
 

Re: How to remove JavaScript from a test page?

No you can't remove javascript. If it has already been executed, then deleting the script won't undo the event bindings.

You will need to use javascript to fight javascript. Either by re-setting the rotating banner code with your variant code, or by unbinding the element altogether (not recommended, but can be done $("#banner").unbind())
Level 2