473,766 Members | 2,060 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 #1
18 4391
In article <bs************ *@news.t-online.com>, ar***@redseven. com
says...
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.


<script src="myfile.js" type="text/javascript"></script>

--
Hywel I do not eat quiche
http://hyweljenkins.co.uk/
http://hyweljenkins.co.uk/mfaq.php
Jul 20 '05 #2
DU
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) ?

I'm not sure what you mean with "extracting ".

There is a bookmarklet available which will allow you to view all
javascript code in a given HTML page.

You can put all script functions and code into a single external
javascript 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?

Again, your question is a bit fuzzy.

If you use a customized bookmarklet, then yes you can figure out inline
scripts and scripts coming from an external file.

One can figure out where in a given HTML document the functions are called.

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


That's because of some desired effects or because some functions should
be executed before some others (like for rollover images) or because
some functions should be executed while the page is loading (e.g.:
document.write( ) calls) or because some other functions should be
executed only once the page has finally and completely loaded (with the
defer attribute or with the onload attribute of the body element or
window object), etc... It all depends on the whole code, the targeted
effects/results, etc.. There is no single and unique rule here.
Overall, it is best to modularize javascript code into defined functions
and it is best to stay away from document.write( ) calls.
In general, I think it is best to create a single unique external
javascript file so that
- your code can be reused
- your code can be cached and reused in the same session, reducing http
downloads and parsing again, making script functions a bit more
responsive, snappy.

DU
Jul 20 '05 #3
"Arthur Connor" <ar***@redseven .com> wrote in message
news:bs******** *****@news.t-online.com...
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

I guess it depends on what your exact usage is. At my site I have two
different applications for js. One handles image swapping and popup display
and depends on having functions defined in advance of them being used so I
have the definitions included right before the end of the <head> as shown in
this scrap:
....
<title>
Bodger's New Day
</title>
<!-- insert image routines -->
<script type="text/javascript" src="theimager. js">
</script>
<!-- end of insert -->
</head>
....

And the actual call is made when a reader clicks on an image of a button and
looks like this:

....
<a href=
"JavaScript : newWindow = openWin( 'gallery/gallery-01-small.jpg',
600, 424 ); newWindow.focus ()">
<img src="button/small.gif" class="gbutt" alt="" title="" width="30"
height="20" /></a>
....

where openWin() is defined earlier and is called with the required
parameters here to create a new window with an image in it and the focus()
pops the new window up over the parent.

In the second main application there is no function definition so nothing
needs to appear in the <head> so the code is placed where it is needed
inline like this:

....
<!-- Start of TheCounter.com Code -->
<script type="text/javascript" src="thecounter .js">
</script>
<!-- End of TheCounter.com Code -->
....

This is done because the js provided by thecounter.com is pretty ugly and
totally blows away any attempts at validation.

Is this what you were looking for?
--
John McGaw
[Knoxville, TN, USA]

Return address will not work. Please
reply in group or through my website:
http://johnmcgaw.com

Jul 20 '05 #4
"Arthur Connor" <ar***@redseven .com> wrote in message
news:bs******** *****@news.t-online.com...
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) ?
outsourced java script looks like the following:

<script src="script/rollover.js" type="text/javascript"></script>

just put your java script code (between the script tags) into a .txt file
and rename it to a .js file
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.


as far as i know (i am not very good at java script) that depends of the
type of java script you are using...

hope i could help.

martin
Jul 20 '05 #5
Where ever you use the <script> tag use it like this:

<script src="myjavascri ptfile.js">
</script>

I think this is the right syntax, I know I'm on the right line!

Chris
Jul 20 '05 #6
ar***@redseven. com (Arthur Connor) wrote in
news:bs******** *****@news.t-online.com:
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) ?
Yup. Anywhere you can write

<script type="text/javascript">som e script</script>

you can also write

<script src="urlforscri pt" type="text/javascript"></script>

In addition to making your code more maintainable, linking to external
scripts also speeds things up because browsers will cache the scripts
rather than reloading them for each page.
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?
Same as if you were inlining the scripts.
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.


You just have to give each section of script its own URL.
Jul 20 '05 #7
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) ?


Of course.

<script type="text/javascript" src="blah.js"></script>

--
Toby A Inkster BSc (Hons) ARCS
Contact Me - http://www.goddamn.co.uk/tobyink/?page=132

Jul 20 '05 #8
While the city slept, Arthur Connor <ar***@redseven .com> feverishly typed:
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) ?


Take the existing javascript code from your page (minus the opening <script
....> and closing </script>) and save that as a file with extension .js. eg,
if you have the following...

<script type="text/javascript">
<!-- Hide

function myFunction()
{
// code here
}

// Dunhidin -->
</script>

.... cut everything from <!--Hide to // Dunhidin --> and save that as, for
example, "myJavascript.j s". Then add the following to your script tag...

<script type="text/javascript" src="myJavascri pt.js">

Hope that help,
Nige

--
Nigel Moss.

Email address is not valid. ni***@nigenetDO G.org.uk. Take the dog out!
http://www.nigenet.org.uk | Boycott E$$O!! http://www.stopesso.com
In the land of the blind, the one-eyed man is very, very busy!
Jul 20 '05 #9
JRS: In article <bs************ *@news.t-online.com>, seen in
news:comp.lang. javascript, Arthur Connor <ar***@redseven .com> posted at
Tue, 30 Dec 2003 19:46:07 :-
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) ?


See <URL:http://www.merlyn.demo n.co.uk/js-other.htm#Effy> , subsection
"Include :- *.js files".

--
© 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 #10

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
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9404
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
10168
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...
0
10008
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9837
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8833
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
5279
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3929
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
3
2806
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.