I searched, I swear. All my keywords were ignored by the search engine. Or I may just suck at searching with the right keywords, but I've been unable to find information about this. Perhaps somebody can elaborate.
I would to like to create a function, included in the header of an HTML page, which calls functions which are defined later, in <script /> tags farther down in the body of the page (I understand this is a terrible idea, but it is a constraint that I have to work with). Unfortunately, the intuitive way (but inherently impossible) of doing this doesn't work: -
function myEarlyFunction() {
-
if(typeof myLateFunction != 'undefined') {
-
myLateFunction();
-
}
-
}
-
...
-
...
-
...
-
<script type="text/javascript">
-
function myLateFunction() {
-
//do stuff
-
}
-
</script>
Is there a way to do this that...well, works? And if so, how?
Thanks so much!
4 2713
I searched, I swear. All my keywords were ignored by the search engine. Or I may just suck at searching with the right keywords, but I've been unable to find information about this. Perhaps somebody can elaborate.
I would to like to create a function, included in the header of an HTML page, which calls functions which are defined later, in <script /> tags farther down in the body of the page (I understand this is a terrible idea, but it is a constraint that I have to work with). Unfortunately, the intuitive way (but inherently impossible) of doing this doesn't work: -
function myEarlyFunction() {
-
if(typeof myLateFunction != 'undefined') {
-
myLateFunction();
-
}
-
}
-
...
-
...
-
...
-
<script type="text/javascript">
-
function myLateFunction() {
-
//do stuff
-
}
-
</script>
Is there a way to do this that...well, works? And if so, how?
Thanks so much!
Try this it will work insha-Allah -
function myEarlyFunction() {
-
if( (typeof myLateFunction != 'undefined') && (typeof myLateFunction == 'function') )
-
myLateFunction();
-
}
-
}
-
Try this it will work insha-Allah -
function myEarlyFunction() {
-
if( (typeof myLateFunction != 'undefined') && (typeof myLateFunction == 'function') )
-
myLateFunction();
-
}
-
}
-
This doesn't work. The problem is that, at the time of parsing, the JavaScript interpreter can find no definition of "myLateFunction " and so this test is never even considered. Try it. Just make an HTML file out of this and see what happens... - <script type="text/javascript">
-
function earlyFunction() {
-
if(typeof lateFunction != 'undefined' && typeof lateFunction == 'function') {
-
lateFunction();
-
}
-
-
}
-
</script>
-
-
Holy crap it's de text. Lol.
-
-
<script type="text/javascript">
-
function lateFunction() {
-
alert("HOLLAH!");
-
}
-
</script>
-
-
It's more text.
-
-
<script type="text/javascript">
-
-
earlyFunction();
-
-
</script>
What I'm looking for is some other mechanism for _dynamically_ (i.e. at RUNTIME) doing function lookups and allowing this sort of behavior. Suggestions? Thanks again!
I apologize. I'm an idiot. I had a typo in my sample file. Misaw is right; this does, in fact work. However, you don't need the (typeof ___ == "function") . Simply conditionalizin g on undefined works just fine.
Try this...
Put the function below within the "<head></head>" tags
<script type="text/javascript">
<!--
function addEvent(elemen tObject, eventName, functionObject)
{
if(document.add EventListener)
elementObject.a ddEventListener (eventName, functionObject, false);
else
if(document.att achEvent)
elementObject.a ttachEvent("on" + eventName, functionObject) ;
}
function earlyFucntion() {
if(typeof myLateFunction != 'undefined') {
myLateFunction( );
}
}
addEvent(window ,'load',earlyFu cntion);
//-->
</script>
then call your
<script type="text/javascript">
<!--
function myLateFunction( ){
alert("fire");
}
//-->
</script>
wherever in the document you want to...
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Olaf Meding |
last post by:
Is there a way to find out if I am using early or late binding given
the reference ("excel" in the example below) returned by Dispatch()?
>>> import win32com.client
>>> excel = win32com.client.Dispatch('Excel.Application')
Thanks much for your help.
Olaf
|
by: Mike MacSween |
last post by:
Had some trouble with Word automation. Sorted it, in the process thought I
would try late binding. Some people reccomend it. So this:
*********************************************************
Public Sub MailMerge(strQuery As String, strTemplate As String)
snip
Dim doc As Word.Document
Dim wrdApp As Word.Application
snip
Set wrdApp = New Word.Application
|
by: Composer |
last post by:
I've read many postings about the problem of Access.References.IsBroken
and the consensus seems to be that late binding is the cure-all.
I have a very complex Access application that needs hundreds of lines
of code to format a Word document in a very specific way.
Because my clients have various versions of Word, the problem of broken
references comes up. I wish Microsoft had implemented a reasonable
solution, so that VBA could do...
|
by: Zlatko Matiæ |
last post by:
I was reading about late binding, but I'm not completely sure what is to be
done in order to adjust code to late binding...
For example, I'm not sure if this is correct:
early binding:
Dim ws As DAO.Workspace
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim rs As DAO.Recordset
|
by: Entwickler |
last post by:
hello,
i have the following problem. i want to write a code that enables the user
to call functions from a unmanaged code .dll at running time . so i have to
use the late binding . i tried the following code but it doesn't walk :
Assembly assemblyInstance =
Assembly.LoadFrom(@"C:\myData\UnmanagedCode.dll");
i don't know if somebody can help me .
Regards,
| |
by: Miro |
last post by:
VB 2003 and Im still new to vb, so i hope i can explain this as best I can.
I have a variable defined as such: ( simple example )
Dim AVariableOfSorts(,) As Object = _
{ _
{"Last", "String", 20}, _
{"First", "String", 20} _
}
|
by: kogrover |
last post by:
ISSUE: COM Excel Sort works with Early Binding, but not Late Binding,
but py2exe only does Late Binding
I have code similar to this (type from notes, so there may be a
typo...)
import win32com.client
xl = win32com.client.Dispatch("Excel.Application")
xl.Visible = False
xl.ScreenUpdating = False
|
by: markww |
last post by:
Hi,
Can someone explain to me what static and dynamic dispatch are and what
the difference is between the two? Do this even occurr in C++?
Thanks
|
by: Aaron \Castironpi\ Brady |
last post by:
Hello all,
To me, this is a somewhat unintuitive behavior. I want to discuss the
parts of it I don't understand.
.... f= lambda: n
....
9
9
|
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...
|
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,...
| |
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...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |