HTML/JavaScript snippet doesnt run second time

Dear Mendixers,   I have a HTML snippet that Onclick triggers a Microflow that open a second page.   However, when I press return on the second page, the HTML snippet of the first page does not work anymore. Who knows how I can ensure the HTML snippet works every time?   Thank you in advance for your support!   Kind regards,   Paul   Update 13 March: the exact same issue occurs with the JavaScript snippet   HTML snippet code: var container = document.getElementsByClassName("mx-name-container5")[0]; $(container).find("span").click(function(){   var microflowInputString = jQuery(this).text();   console.log(microflowInputString); //We create a new object of a new entity because the Mendix client API doesn't have an interface for strings being given as an input into microflows{   entity: "Data_Import.LookupValue",     callback: function(obj) {  //We set the word from the form as an attribute part of your new entity, I used "Word" as an example, make sure this matches your new entity obj.set("Value",microflowInputString);{     params: {             actionname: "Breakdown.ACT_LookupWord",         applyto: "selection",               guids: [obj.getGuid()],         //origin: this.mxform         },     error: function(error) {         alert(error.description);     } });     },     error: function(e) {         console.log('an error occured: ' + e);     } }); });  
2 answers

I found the solution after some testing, so here giving back to the community.

The below row of code only works one time for a reason I don't understand.

Replacing that line of code with the line underneath solved the issue.


var container = document.getElementsByClassName("mx-name-container5")[0];

var container = $(".mx-name-container5");


I found the jQuery selector method using this link:


Cheers all!


It may be possible to make the script kick off again using the onpopstate eventhandler:

The onpopstate property of the WindowEventHandlers mixin is the EventHandler for processing popstate events on the window.

popstate event is dispatched to the window each time the active history entry changes between two history entries for the same document. If the activated history entry was created by a call to history.pushState(), or was affected by a call to history.replaceState(), the popstate event's state property contains a copy of the history entry's state object.


Found via someone who had a similar problem.