Gordon
Gordon

Reputation: 61

Browser ignores Javascript file

I try to add a Javascript file to my page. But the Browser ignores the file link completely.

The Script-Tag is correct in the source code (in the browser). When I copy the file path and access it directly, the file is there and can be found. I also tried to check it with Chrome and the network tab is not showing that the browser is even trying to load the file. Does anybody has an idea what that could be?

The Flask code:

    <!DOCTYPE html>
<head>
    <title>{{ title }}</title>
    <link rel="stylesheet" type="text/css" href="{{ url_for('static',filename='css/style.css') }}">
    <script type="text/javascript" href= "{{ url_for('static',filename='js/jscolor.js') }}"></script>
</head>

<body>

The source code in the browser:

<!DOCTYPE html>
<head>
    <title></title>
    <link rel="stylesheet" type="text/css" href="/static/css/style.css">
    <script type="text/javascript" href= "/static/js/jscolor.js"></script>
</head>

<body>

Everything looks fine. The file exists and the path is correct. But it gets ignored. (Checked in Chrome and Firefox).

Upvotes: 0

Views: 241

Answers (1)

Zailef
Zailef

Reputation: 715

Script tags have a source (src) attribute, not a href. Just replace that and it should be fine.

In the case of:

<script type="text/javascript" href= "/static/js/jscolor.js"></script>

Replace with:

<script type="text/javascript" src= "/static/js/jscolor.js"></script>

Upvotes: 3

Related Questions