简体   繁体   中英

Javascript embedding

Every time I try embedding a URL no matter which url I use it always gives me this error

Uncaught SyntaxError: Unexpected token <

the code I use is

<script src="URL" type="text/javascript">
        </script>

It does not matter which URL I point too it just always gives that error.

Uncaught SyntaxError: Unexpected token <

That means there's HTML markup in a JavaScript file. So either the script tag you're showing us is in a JavaScript file, or the JavaScript file that it's referencing contains HTML.

When putting JavaScript code in an HTML file, you need to wrap it in script tags:

<script type="text/javascript">
    var foo = 'foo';
</script>

However, when putting JavaScript code in a JavaScript file, you don't need HTML tags. Because it's not HTML:

var foo = 'foo';

Putting one kind of code in a file meant to be another kind of code results in a syntax error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM