473,772 Members | 2,510 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to outsource Javascript code from html code ?

Is there a way of extracting the Javascript code from the "normal" HTML code
(e.g. similar to CSS code which can be put into a separate file) ?

If you offer a solution: can I determine in your solution where and which part
of the code should be placed/inserted in the main HTML code?

Sometimes a Javascript functionality is split up to several parts and/or
it makes a big difference where the Javascript code should run/be called
(e.g.
- in the <HEAD>....</HEAD> or
- at the beginning just behind the <BODY> tag
- at the end just before the </BODY> tag.
.....)

Arty

Jul 20 '05
18 4392
Arthur Connor wrote:
Is there a way of extracting the Javascript code from the "normal"
HTML code (e.g. similar to CSS code which can be put into a separate
file) ?

If you offer a solution: can I determine in your solution where and
which part of the code should be placed/inserted in the main HTML
code?

Sometimes a Javascript functionality is split up to several parts
and/or
it makes a big difference where the Javascript code should run/be
called (e.g.
- in the <HEAD>....</HEAD> or
- at the beginning just behind the <BODY> tag
- at the end just before the </BODY> tag.
....)

Arty


Yes, you can do this.

Add a line in the head of your code such as the following;

<script language="JavaS cript" src="include/bfinclude.js"></script>

(this includes a javascript file which is located in the directory
'include')

Note that the above looks very similar to the existing markers for inline
javascript code; instead of having the routines listed, it uses the 'src'
parameter to locate a source file. The contents of the javascript file
should be just javascript, nothing else.

For example, the code below would be the entire content of the bfinclude.js
file (including the html comments)

<!--
function MM_reloadPage(i nit) { // Reloads the window if Nav4 resized
if (init==true) with (navigator) {if
((appName=="Net scape")&&(parse Int(appVersion) ==4)) {
document.MM_pgW =innerWidth; document.MM_pgH =innerHeight;
onresize=MM_rel oadPage; }}
else if (innerWidth!=do cument.MM_pgW || innerHeight!=do cument.MM_pgH)
history.go(0);
}
-->

HTH,

Pete.
--

Peter Connolly | Macromedia Certified Dreamweaver MX Developer
http://www.acutecomputing.co.uk
Derby
UK

Jul 20 '05 #11
In article <bs************ *******@news.de mon.co.uk>, "Peter Connolly"
<no************ *@nospamrequire d.com> writes:
Add a line in the head of your code such as the following;

<script language="JavaS cript" src="include/bfinclude.js"></script>
It is wiser to use type="text/javascript" than it is language="javas cript" [1]
(this includes a javascript file which is located in the directory
'include')

Note that the above looks very similar to the existing markers for inline
javascript code; instead of having the routines listed, it uses the 'src'
parameter to locate a source file. The contents of the javascript file
should be just javascript, nothing else.

For example, the code below would be the entire content of the bfinclude.js
file (including the html comments)
1) The "html comments" are not needed in any browser less than 10 years old.
2) They are not "html comments", they are part of the script block and as such
are part of the script.
<!--
function MM_reloadPage(i nit) { // Reloads the window if Nav4 resized
if (init==true) with (navigator) {if
((appName=="Ne tscape")&&(pars eInt(appVersion )==4)) {
document.MM_pgW =innerWidth; document.MM_pgH =innerHeight;
onresize=MM_re loadPage; }}
else if (innerWidth!=do cument.MM_pgW || innerHeight!=do cument.MM_pgH)
history.go(0 );
}
-->


[1] Now I remember why I don't use Dreamweaver, I prefer reliable code.

See the FAQ with regards to object detection.
--
Randy
Jul 20 '05 #12
HikksNotAtHome wrote:
It is wiser to use type="text/javascript" than it is
language="javas cript" [1]

1) The "html comments" are not needed in any browser less than 10
years old. 2) They are not "html comments", they are part of the
script block and as such are part of the script.

Fair comment, and good advice. Thanks.

See the FAQ with regards to object detection.


Thanks, but I do very little with Javascript, so I'm not staying around! I
only dropped in to see where my response had disappeared to, as it didn't
show up in the newsgroup I had replied to; the OP had cross-posted, but I
didn't notice at the time - I normally remove cross-postings before
replying.

Regards,

Pete.
--

Peter Connolly | Macromedia Certified Dreamweaver MX Developer
http://www.acutecomputing.co.uk
Derby
UK

Jul 20 '05 #13
You certainly can, its called a .JS file - see
http://www.javascript-fx.com/general...aljs/help.html or search the web
for more info.

Arthur Connor wrote:
Is there a way of extracting the Javascript code from the "normal" HTML code
(e.g. similar to CSS code which can be put into a separate file) ?

If you offer a solution: can I determine in your solution where and which part
of the code should be placed/inserted in the main HTML code?

Sometimes a Javascript functionality is split up to several parts and/or
it makes a big difference where the Javascript code should run/be called
(e.g.
- in the <HEAD>....</HEAD> or
- at the beginning just behind the <BODY> tag
- at the end just before the </BODY> tag.
....)

Arty


Jul 20 '05 #14
JRS: In article <20************ *************** @mb-m25.aol.com>, seen in
news:comp.lang. javascript, HikksNotAtHome <hi************ @aol.com>
posted at Wed, 31 Dec 2003 23:57:27 :-
In article <bs************ *******@news.de mon.co.uk>, "Peter Connolly"
<no*********** **@nospamrequir ed.com> writes:

For example, the code below would be the entire content of the bfinclude.js
file (including the html comments)


1) The "html comments" are not needed in any browser less than 10 years old.
2) They are not "html comments", they are part of the script block and as such
are part of the script.


A) They may be useful if the page is being processed by software other
than a browser.

B) They are HTML comments, since they are for use when the script tag is
not recognised.

<!--
function MM_reloadPage(i nit) { // Reloads the window if Nav4 resized
if (init==true) with (navigator) {if

if (init) ... should suffice.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 20 '05 #15
In article <y7************ **@merlyn.demon .co.uk>, Dr John Stockton
<sp**@merlyn.de mon.co.uk> writes:
1) The "html comments" are not needed in any browser less than 10 years old.
2) They are not "html comments", they are part of the script block and assuch
are part of the script.


A) They may be useful if the page is being processed by software other
than a browser.


Agreed that they may be useful in software other than a browser. But that still
doesn't change the content type of a script block.
B) They are HTML comments, since they are for use when the script tag is
not recognised.


http://tinyurl.com/27c6l

Leads to a discussion not long ago (Nov 9, 2003) about whether they are HTML
comments or part of the script block. To quote Jim Ley:

<quote>
That's a javascript comment, not an HTML one, and it can cause no harm
(in XHTML things are different of course)


The string "<!--" begins an HTML comment.


The content model of SCRIPT is CDATA - you're not allowed comments
inside it, therefore that must be part of the script, and passed to
the script engine. Certainly it's not part of ECMAScript, but that is
not an HTML comment - they're not legal inside SCRIPT blocks (this is
the change with XHTML of course where the content model of script
changed to PCDATA which allows comments.)

It's either a javascript comment, or something that the javascript
engine accepts as if it was a comment - it's passed as is via the HTML
parser.

Jim.
</quote>

So, they are part of the script block, and not an HTML comment.
--
Randy
Jul 20 '05 #16
hi************@ aol.com (HikksNotAtHome ) writes:
So, they are part of the script block, and not an HTML comment.


The point that Dr. Stockton made, and that I wish I had made to Jim
Ley then, is that whether it is part of the script block or an HTML
comment depends on 1) the version of HTML and 2) the browser.

The reason to put the <!-- there at all, is that *some* browsers treat
it as the start of an HTML comment. Other browsers treat it as part
of the script block (and actually break ECMAScript compliance to do it:
var x = 2;
if (1 <!-- x
) { alert("foul");}
is a valid syntactically correct ECMAScript program that should not
call the function "alert", but does in the browsers I checked - IE 6,
Opera 7 and Moz FB).

But the reason to write the <!-- at all, is to have it interpreted as
an HTML comment. So, at least partially, it *is* an HTML comment.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #17
In article <r7**********@h otpop.com>, Lasse Reichstein Nielsen <lr*@hotpop.com >
writes:
But the reason to write the <!-- at all, is to have it interpreted as
an HTML comment. So, at least partially, it *is* an HTML comment.


No, its part of a script block that is interpreted as an HTML comment not a
true HTML comment.

All of it is purely semantical though until you escape the HTML world.
--
Randy
Jul 20 '05 #18
hi************@ aol.com (HikksNotAtHome ) writes:
No, its part of a script block that is interpreted as an HTML comment not a
true HTML comment.
To Netscape 1, it is an HTML comment, because that browser doesn't
know what a script block is. As a well behaved HTML client, it ignores
unknown tags and finds the HTML comment inside.

The reason to add the <!-- and //--> is to make Netscape 1 and
contemporary browsers treat it as an HTML comment. Later browsers
gracefully ignores <!-- and --> inside script blocks, since they are
not placed there for these, smarter, browsers. It is added for one
purpose only: To be used as an HTML comment.
All of it is purely semantical though until you escape the HTML world.


To where? :)

The problem might be that it is the difference between HTML syntax and
actual browser semantics.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #19

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1765
by: Arthur Connor | last post by:
Is there a way of extracting the Javascript code from the "normal" HTML code (e.g. similar to CSS code which can be put into a separate file) ? If you offer a solution: can I determine in your solution where and which part of the code should be placed/inserted in the main HTML code? Sometimes a Javascript functionality is split up to several parts and/or it makes a big difference where the Javascript code should run/be called (e.g. -...
0
1394
by: Michael Douma | last post by:
This is about a small subcontracting project. This is an interesting project which produces interactive graphs of the gnutella network. We are updating a python project written by students at Berkeley a few years ago. This project is to switch from an out-dated data host to a new one. The following is a link to the source code for a python project which makes radial maps of gnutella hosts: ...
0
1604
by: adminfreelance | last post by:
http://www.freelance.eu freelance, programming, outsourcing, programmer, outsource, php programming, mysql,mysql database database Freelance.eu , temporarily: post your projects for free and free webmaster and programmer signup!
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10039
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8937
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6716
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4009
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2851
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.