0

When I launch this in chrome, nothing appears on the page.

<!DOCTYPE html>
<head><title>test 4000</title><head>
<body>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
document.writeln("test")
</script>
</body>
</html>
7
  • 3
    you shouldn't put inline scripts in a script tag that references an external script Commented Aug 22, 2014 at 21:29
  • Maybe you try to open this file right from you disk (I mean not from server). In this case Chrome trying to find including script as file://ajax.googleapis.com... Commented Aug 22, 2014 at 21:30
  • 1
    See stackoverflow.com/questions/6528325/… Commented Aug 22, 2014 at 21:30
  • 1
    @JezD ...which doesn't work if you're running it as a local file. src="// only works when running from a webserver. Commented Aug 22, 2014 at 21:32
  • 1
    @Guam you've not closed your <head> tag, you seem to be opening one inside another and closing neither Commented Aug 22, 2014 at 21:34

1 Answer 1

6

you are inserting code in a script tag that you are also using to load an external script (jQuery). you should either do the one or the other.

<script>
    document.writeln("test");
</script>

if you want both do:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
    document.writeln("test");
</script>

the reference states:

If the src has a URI value, user agents must ignore the element's contents and retrieve the script via the URI.

you do not need to include jQuery to use document.writeln()

Sign up to request clarification or add additional context in comments.

5 Comments

The "type=text/javascript" attribute is redundant, btw. You can safely take it away.
The relevant reference is w3.org/TR/REC-html40/interact/scripts.html#edef-SCRIPT which says: “If the src has a URI value, user agents must ignore the element's contents and retrieve the script via the URI.”
@hugomg right. this is html5 only. thanks.
The reason that this behaviour is in the html5 standard is because it was already implemented by every browser out there. So in practice, ommiting the script type is also an "html4" feature. (This is also why the html5 doctype declaration is the way it is)
html 4.01 reference says The scripting language is specified as a content type (e.g., "text/javascript"). Authors must supply a value for this attribute. There is no default value for this attribute. although browsers assumed it anyway.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.