Content pages insert javascript

Okay fw7 experts, need some help.

My understanding is that a content page loaded into an existing view, will NOT load the js or style tags from the page. The process is to insert those in the app.js file…so far so good.

I added the following which very nicely gets added to the content page and works properly.

$(document).on('page:init', function (e, page) {
  switch (page.name) {
    case "review":

      var s = document.getElementsByTagName('script')[0];
      var sc = document.createElement('script');
      sc.type = 'text/javascript';
      sc.async = false;
      sc.src = 'https://maps.googleapis.com/maps/api/js?key=REDACTED-KEY&callback=initAutoComplete&libraries=places';
      s.parentNode.insertBefore(sc, s);
}

HOWEVER, if I navigate to another page, and use the back function, the script is inserted again. I thought by doing this on page:init it would only execute once???

I’ve read that it might be multiple views, but I am not seeing anything other than view-main.

Ideas on how to get this script into a content page only once?

1 Like

Hello @mebeingken I am experiencing the same problem. Trying to display a map on a content page. I am unsure where to put the code you provided. In a tag on the content page itself or in the index.html? Could you help me out please?
Best,
Albert

Hi Albert,

The approach above was incorrect…In my current code I simply have the source link included on my index page like any other script to be used. I use the FW7 Core framework, so I’m not sure how it is to be used when using FW7 with App Connect.

Thank you for the quick reply, Ken! We solved our problem just now. Heres a description: