Framework7 - script not working in another page

Hello everyone,

I am working on a project. but I am stuck with something. I have a main index page and a second page that is accessible by a route by clicking on a button. In that page I link to a .js script. just like this:

But it does not run the script.js. When I put the script in the index page it does not work too. But when I put the css of the second page in the index then it will run the css for the second page. Please can someone help me out?!

I am still a beginner with framework7, so I don’t have any idea anymore how to fix this issue.

I hope someone can help me out. Thanks anyway!

Such pages are loaded via ajax, so script tags can’t work there

Thankyou for your reply!

So what could I do in order to make it work in my second page?
Because in the index page it does work.

You need to put your script inside pageinit page-data=your 2ng page

Oke, but how can I do that? I have zero experience with f7

There is a way to use the css or js . If your js file do not contain a framework7 specific syntax , then, you can refer it in your second_page.f7.html like:-

<script src="static/second.js"></script>

Put your js file is static file directory.
If your file contains something which is specific to framework7 like dom library($$) , you will need to use app.js , edit your ‘app.js’ as:-


for above code to work, your second-js must be in js directory and data-name attribute of your second page must be "second_page"

1 Like

Thankyou all! It is fixed now.

I tried it but it didn’t work out

Can you explain what you tried and paste some code related because it’s still working now for me

Capture I added this to my HTML file

Capture1 and this to my app.js

Use page init in your app.js or my-app.js