473,385 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Load a script and process it inmediately

Hello.

I have a script (S1) that depends on other script (S0) so I have to
include both scripts in all pages:

<script type="text/javascript" src="/js/S0.js"></scrip>
<script type="text/javascript" src="/js/S1.js"></scrip>

I have read that is is posible to load one script from any other:

function loadScript (scriptUrl) {
var head = document.getElementById("head");
var script = document.createElement("script");
script.type = "text/javascript";
script.src = url;
head.appendChild(script);
}

Supose that I want to load S1 from S0:
S0.js:
../..
loadScript('S1.js');
s1Function(); // A function defined inside S0

index.shtml:
<head>
<script src="S0.js">
</head>

The code above doesn't work because S1.js it is loaded after the end of
S0.js and not when I load S1.js with loadScript.

¿It is posible to load S1.js right after invoke loadScript('S1.js') so I
could use S1 functions' in S0.js?

Thanks.
Jul 23 '05 #1
1 1400
Jesús Ángel wrote:
I have a script (S1) that depends on other script (S0) so I have to
include both scripts in all pages:

<script type="text/javascript" src="/js/S0.js"></scrip>
<script type="text/javascript" src="/js/S1.js"></scrip>
There is a "t" missing in both end tags, but maybe that's only a typo
duplicated by copy and paste.
I have read that is is posible to load one script from any other:

function loadScript (scriptUrl) {
if (document.getElementsByTagName)
{
var head = document.getElementById("head");
Instead:

var head = document.getElementsByTagName("head");
if (head && (head = head[0]) && document.createElement)
{
var script = document.createElement("script");
if (script && head.appendChild)
{
script.type = "text/javascript";
script.src = url;
head.appendChild(script);
}
}
} }

Supose that I want to load S1 from S0:
S0.js:
../..
loadScript('S1.js');
s1Function(); // A function defined inside S0

index.shtml:
<head>
<script src="S0.js">
</head>

The code above doesn't work because
there are the following items missing:

- the "id" attribute value "head" for the "head" element, if you
want to use getElementById() instead of getElementsByTagName()
- the "title" element
- the "type" attribute value for the "script" element
- the </script> tag.
S1.js it is loaded after the end of
S0.js and not when I load S1.js with loadScript.
No, see above.
¿It is posible to load S1.js right after invoke loadScript('S1.js') so I
could use S1 functions' in S0.js?


No, because that would mean that both script files would depend on each
another (cross dependency). loadScript() only works within HTML files
and on few browsers, i.e. only if there is a document which provides
the object model that is required by the method.
PointedEars
--
But I thought you'd like it...
Jul 23 '05 #2

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

Similar topics

5
by: Mike Wasmer | last post by:
Is there an event that signifies the end of a page load?
1
by: Ray in HK | last post by:
What are the differences between LOAD DATA INFILE and LOAD DATA LOCAL INFILE ? I found some web hosting company do not allow using LOAD DATA INFILE but allow LOAD DATA LOCAL INFILE. The reason...
4
by: veronica24 | last post by:
I need some help. I am currently running a load script on db2 version 7 on an AIX 5.1.02 server in our production environment. We have upgraded our test server with db2 version 8 AIX 5.2..03. ...
12
by: Sharon | last post by:
I’m wrote a small DLL that used the FreeImage.DLL (that can be found at http://www.codeproject.com/bitmap/graphicsuite.asp). I also wrote a small console application in C++ (unmanaged) that uses...
0
by: hy | last post by:
Hi all, I got a problem to restore back the selected upload file after i fired a radio button that will call the server script to do the process. In my aspx page, i have an upload textbox to...
19
by: Alex Madon | last post by:
Hello, I am testing a web application (using the DBX PHP function to call a Postgresql backend). I have 375Mb RAM on my test home box. I ran ab (apache benchmark) to test the behaviour of the...
19
by: natG | last post by:
On a warehouse app, our Java clients constantly load/insert rows into the db. I would like to throttle these inserts (1.5 million rows per hr) from the Java app, based on current 'busy state' of...
3
by: Sunny | last post by:
Hi, Can someone tell me, How to load the Body Html from a text file that contains javascript. to Manage my files I am creating an Index Page. <html> <head> <meta http-equiv="content-type"...
4
hemantbasva
by: hemantbasva | last post by:
We have designed an aspx page having five ajax tab in it. the data of first four are designed on page whereas for the fifth tab it renders a user control named MYDOMAIN. in the tab container's even...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.