Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello!

I was using bootstrap modal with bootstrap.min.js in Scripts directory of my project. Suddenly it stops working...

Not working:

<script type="text/javascript" src="Scripts/bootstrap.min.js"></script> 

In this case everything looks to be ok - there is even no error in browse console while loading bootstrap.min.js file - just nothing happened on click...

Working:

<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>  

Files are placed in Scripts folder like always, I tried change file on disk, to this from link - without any reason.

There is no error in browser console, just modal window does not appear. Everything is working only when I change to full URL.

What can be the reason...?

What I have tried:

Few versions of bootstrap files, removing files from Scripts directory with
src="Scripts/bootstrap.min.js"
- then I can see error in browser console (jquery loaded, but can't find .modal function - correct information in this case)
Posted
Updated 7-Oct-21 2:26am
v2

1 solution

The local script is using a relative source. The file must be in a folder called Scripts within the same folder as the current URL.

For example, if your URL is: https://somesite.local/folder/page1.aspx
Then the script file must be: https://somesite.local/folder/Scripts/bootstrap.min.js

If your URL is: https://somesite.local/folder/sub-folder/page1.aspx
Then the script file must be: https://somesite.local/folder/sub-folder/Scripts/bootstrap.min.js

If the scripts folder is in the root of your application, use an app-relative path:
ASPX
<script src="<%= ResolveClientUrl("~/Scripts/bootstrap.min.js") %>"></script>

If it still doesn't work, then you need to use your browser's developer tools to see why the script file is not loading.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900