HTML/JavaScript snippet doesnt run second time

1
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 mx.data.create({   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);     mx.data.action({     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);     } }); });  
asked
2 answers
3

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:

https://www.w3schools.com/jquery/jquery_ref_selectors.asp

 

Cheers all!

answered
1

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.

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

Source: https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onpopstate

Found via someone who had a similar problem.

 

answered