wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes Can <script> having src attribute contain any body or function? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Can <script> having src attribute contain any body or function?" Watch "Can <script> having src attribute contain any body or function?" New topic
Author

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

Har Kaur
Greenhorn

Joined: Jul 22, 2011
Posts: 4
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

Joined: Aug 01, 2010
Posts: 40

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.


-Abhishek
I came to this world on a Learner's License
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60056
    
  65

And, then answer is no.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can <script> having src attribute contain any body or function?
 
Similar Threads
Jquery function is not working
Getting duplicate values on the onChange event of dropdown list
YUI listener problem
my overlay box works in Firefox, but fails in IE8
JSP Not able to Identify the JS, CSS file path