how to call the file function . js

Asked

Viewed 1,696 times

0

I am unable to call a javascript function from a file. Ex:

Filing cabinet: javascript inside the briefcase raiz/scripts/javascript.js

function responsivo () {
    $('#responsivo').popover({
        //trigger: 'manual',
        placement: 'bottom',
        html: true,
        title: 'O que é um site ou software responsivo?',
        content: $('#Responsivo').html()
    }).popover("show");
};

view that’s in the folder raiz/views/home/Index.cshtml

<h3 class="div1Texto2">Sites, Softwares e Lojas Virtuais 100% integrados e <span id="responsivo">responsivos</span></h3>

tag head:

<script src="~/Scripts/javascript.js"></script>

when I turn the page it doesn’t work, but if I put that function on the page it works normally.

I tried to do it too, but it didn’t work:

<script type="text/javascript">
    responsivo();
</script>

Obs: I was able to call by putting onload="responsive()" in the tag , but if you have many functions as I do?

1 answer

1

You can use two alternatives, or the relative path, which is relative to the current file. So if this is the location of your index : raiz/views/home/ then the path to your js file, would be <script src="../../scripts/javascript.js"></script>. At each ../ It’s like I’m gonna turn a briefcase around. The other alternative would be to use the absolute path, which is to place the link from where this located the file, would be something like: <script src="http://www.seusite.com/scripts/javascript.js"></script>. I think that’s it, I hope I helped. I didn’t understand your remark...

  • I did so <body onload="responsive ()">

  • and so it worked?

  • Not yet tested, I am on the street now, but coming I will test. Thanks for while.

  • Blz, anything just comment. And in case you use the functions in the tags, you could use Jquery too.... without having to put right in the tag

  • @Fabio Souza also have this problem. I am using windows and do not know whether to use or / to enter subfolders. When I put javascript code directly into html it works.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.