I have a php web based application with dhtml menu.
Each time user click menu Item, the page loads external php page into a div container in that page and then load external javascript as the clientside event handler of that loaded page.I load both of them using ajax method.
The problem is: how to call a function of that external javascript soon after the external javascript file loaded into main page?
I tried eval(functionNa me()) but it returns error Object Required.I got confused because the functionName is declared in that external javascript.I tried to catch the readyState of XmlHttpRequest and the result shows that by the time i call functionName() XmlHttpRequest readyState is still 1.So then i puut a loop 'while do' that say when the readyState reach 4,call functionName() n then i got this Browser Message that say something like script make browser run slowly and nothing happened not even close to my expectation...
Please help me.. feel desperate now..
7 2261 hsriat 1,654
Recognized Expert Top Contributor
The external function should be considered as a part of the page (technically window) as soon as readystate changes to 4.
So instead of using any do while loop or using any eval, just call the function at the end of your onreadystatecha nge function. That may solve your problem.
Hei thanku for your reply...
I have tried that one too.. but it still return object required message...
heres what code looks like
lets just say my main page is Main.php
and my child page is Child.php
my child exsternal js file is Child.php.js
function i would like to call in external js file is child_Load() - if(xml.readyState==4 && xml.status==200)
-
{
-
includeExternJScript('contentScript','Child.php.js',xml.responseText);
-
child_Load(); //this return object required message error
-
-
}
-
-
function includeExternJScript(divId,scriptUrl,xmlResponse)
-
{
-
get object 'head' tag
-
create element script;
-
set element script.text = xmlResponse;
-
add element script to object head as child
-
}
hsriat 1,654
Recognized Expert Top Contributor - function includeExternJScript(scriptUrl)
-
{
-
var js=document.createElement('script')
-
js.type = "text/javascript";
-
js.src = scriptUrl;
-
document.getElementsByTagName("head")[0].appendChild(js);
-
}
I think the function includeExternJS cript() should be like this. What would xmlResponse has to do with the script?
Once you run this function, the external script would take time to be fetched from the server. So it would again need some time before you call your function.
So for that, either instead of calling load_child() in this script, call it at the end (append load_child(); to the last line) of that dynamically loaded js.
Or you should wait until the js is actually loaded.
For that, create a function like this: - do_child_Load() {
-
if (window.child_load)
-
child_load();
-
else setTimeout("do_child_Load()", 100);
-
}
and call do_child_load() instead of child_load().
But anyhow, the first thing is recommended as the second may not work in some cases.
- function includeExternJScript(scriptUrl)
-
{
-
var js=document.createElement('script')
-
js.type = "text/javascript";
-
js.src = scriptUrl;
-
document.getElementsByTagName("head")[0].appendChild(js);
-
js=document.createElement('script')
-
js.text = "child_Load()";
-
document.getElementByTagName("head")[0].appendChild(js);
-
}
-
Is that how i should write the code?
I will try that
Anyway thanks
hsriat 1,654
Recognized Expert Top Contributor
No... not like this, but in your external js file, append this line in the end.
thank u for your help.. finally i got what i need.. here's the code ive been modified - function XMenu_OnClick(itemId,itemValue)
-
{
-
var obj;
-
var url;
-
-
for(var i=0;i<oXMenu._menuItem.length;i++)
-
{
-
if(oXMenu._menuItem[i]._id==itemId && oXMenu._menuItem[i]._isinduk==0)
-
{
-
contentDiv.innerHTML = '';
-
removeExternJScript('contentScript');
-
-
url = oXMenu._menuItem[i]._direktori+'/'+oXMenu._menuItem[i]._nmform;
-
scripturl = "../Resources/Js/"+oXMenu._menuItem[i]._direktori+"/"+oXMenu._menuItem[i]._formpage+".js";
-
-
obj = new Object();
-
obj.contentid='content';
-
obj.url = url;
-
oXAjaxLoader = new XAjaxLoader(obj);
-
oXAjaxLoader.showResult();
-
includeExternJScript(scripturl);
-
ToolbarState_Content();
-
-
break;
-
}
-
}
-
}
-
-
function includeExternJScript(scriptUrl)
-
{
-
var oHead = document.getElementsByTagName('head').item(0);
-
var oScript = document.createElement('script');
-
oScript.language = "javascript";
-
oScript.type = "text/javascript";
-
oScript.id = 'contentScript';
-
oScript.src = scriptUrl;
-
-
oHead.appendChild(oScript);
-
callChildInit();
-
}
-
-
function removeExternJScript(sId)
-
{
-
var oHead = document.getElementsByTagName('head').item(0);
-
var oScript = document.getElementById(sId);
-
-
if(oScript!=null)
-
{
-
oScript.src='';
-
oScript.text='';
-
oHead.removeChild(oScript);
-
}
-
}
-
-
function callChildInit()
-
{
-
if(oXAjaxLoader.oXml.readyState==4)
-
Page_Load();
-
else
-
setTimeout("callChildInit()",100);
-
}
hsriat 1,654
Recognized Expert Top Contributor
That's good you got it working. :)
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Jim Mitchell |
last post by:
It seems that I can just insert <href=# onclick:javascript:CallJava()>Go
Java</a> into the text property of a label control to call a Javasript
function.
It seems to be a very useful tool.
1) Any reason not to do it?
2) Is there a better way?
Thanks in advance.
|
by: techy techno |
last post by:
Hii
Just wanted to know how can I decorate my texboxes and Listmenu which is
called from a JS file using the following code below:
document.write("<SELECT NAME='cur2' ONCHANGE='cconv1();'>");
document.write("<OPTION VALUE='0.345066110642241'>Argentina Peso
</OPTION>");
document.write("<OPTION VALUE='0.790200069503053'>Australia Dollar
|
by: Bartosz Wegrzyn |
last post by:
Please look at my code.
I do validation of my form before I submit it.
I want to be able to to press one form button without running validating
script.
I just want to go directly to my php script.
I tried to do this
onclick="document.form1.submit()" but than the button value is not posted
and my php script is not working.
|
by: AshuPd |
last post by:
Hi all !!!
I am fighting with a very interesting issue...
What i need is to link a javasript with a imagebutton control which is already on a datalist. the problem is, if i place the control out of the DL it works fine but the id of the control looses its declaration as it is placed at the DL.
Pl. some one give some idea to solve it...
TIA
Ashutosh
|
by: Yasantha |
last post by:
hi,
how to call a text box to javasript
| |
by: sandeepdesai |
last post by:
Hi.. i am new to javascripts,
i am using a addRow scipt to add rows to a table dynamically.
one of the cells(say cell2) in a Nth row needs to be hyperlinked to another script.
for example:
function addRow() // the add row script
{
|
by: pedalpete |
last post by:
Hi All,
I'm using Bill Scott's YUI carousel v5.6, and I've run into a crazy looping javascript for some reason, and I can't seem to get around it.
The carousel loads a bunch of items, 7 of which are visible, and then via ajax it loads more and ads them to them on to the list as it goes.
If a user selects one of the items, that item scrolls to the middle and is highlighted.
I've got all this working, except that when a user clicks,...
|
by: bilibytes |
last post by:
Hi,
i have been creating an ajax aplication on my website and it worked as i expected it to work on Safari and Firefox, until i upgraded to Firefox 3.
It doesn't work either on windows.
the url is:
http://www.whichselect.com
I have created an event, that was triggered onmouseover the horizontal nav bar
|
by: dupdupdup |
last post by:
Hello there, im needed to develop a gallery for this website.
im using hotspots to go to my frames in my flash
Each hotspot goes to each frame.
The flash is loaded properly.
When i right click and click play it goes to the next frame.
But the Hotspots just dont work with IE.
For your information: This works with other browsers like firefox, safari and Opera.
MY HEADER
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"...
|
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: 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...
| |
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,...
|
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: 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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |