• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can <script> having src attribute contain any body or function?

 
Har Kaur
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

I am new to JS and have a rather naive question.

I am trying the below code:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Demo</title>
</head>
<body>
hi
<script src="abcs.js">
function func_try()
{alert("checking");
}
</script>function fun

<script>

c_onload(){
alert("welcome to JS world");
func_try();
}
</script>

<script>
window.onload= func_onload();

</script>
</body>
</html >


Here abcs.js is an empty file present in the same location of this html.
On execution alert("welcome to JS world"); works but alert("checking"); doesn't work.

Is this because of the src of javascript included as abcs.js. If yes then whats the reason?

 
Abhishek Ralhan
Ranch Hand
Posts: 40
Chrome Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have never seen/tried it. But what's the big deal, just put the body script in another <script> tags and go ahead, just likeits donr in the second <script> tag of your code.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65123
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And, then answer is no.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic