Forum Moderators: open
e.g.
html file code - <script src="file1.js" type="text/javascript">
call whatever() ...
ext javascript file1.js code - function whatever()..
set a cookie ...
alert("whatever")
ext javascript file2.js code - function whatever()..
check if cookie ...
window.open()...
Regards Jerry
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>JS EXTERNE</title>
<script src='file1.js' type='text/javascript' /></script></head>
<body>
<input type="button" onclick="fonction1()" value="go" />
</body>
</html>
a first external js file:
file1.js
function fonction1(){
var NewScript=document.createElement('script')
NewScript.src="file2.js"
document.body.appendChild(NewScript);
fonction2();
} a second js file
function fonction2(){
alert('told you I would get there!')
} Seem to work also with firfox against all odds!
Tried for several days now before dropping it here at Webmasterworld, but it looks like it always gets stuck at the function call in script1 to that function in script2. Same problem with your code SpaceFrog.
monsterhead you say it is possible, I would appreciate it if you would be so kind to drop an example for code in script1 calling the function in script2.
Here is the actual problem I am trying to solve:
I have several html files in different directories that need to set a temp cookie, but not set from their own directory but set from the root directory. So that is why I make these pages call ext. script1 and now I want ext. script2 in the root to set the cookie. Already had it working with the popwin myself just as Spacefrog suggested. But it's more a band-aid solution cause it involves opening an extra popwin that needs to be closed immediately when the cookie was set. Would be nice if this is possible with two communicating external scripts. Then there is no need to open and close a popwin.
thanks
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>JS EXTERNE</title>
<script src='file1.js' type='text/javascript' /></script></head>
<body>
<input type="button" onclick="fonction1()" value="go" />
</body>
</html>
a first js file:
file1.js
function fonction1(){
var NewScript=document.createElement('script')
NewScript.src="file2.js"
document.body.appendChild(NewScript);
fonction2();
}
a second js file
function fonction2(){
alert('her I am!')
}
And monsterhead thanks for the hint :-)
this is why I develloped this :
function AddLibrary(file){
var NewScript=document.createElement('script')
NewScript.src=file+".js"
document.body.appendChild(NewScript);
}function fonction1(){
AddLibrary('file2')
fonction2();
}
this allows you to call a js library from your html page
SOLVED Problem A with your previous code:
Have several html files in different directories that need to call ext. script1 which in turn calls ext. script2
UNSOLVED Problem B:
Thought when ext. script2 (located in the root dir and with a function to set a cookie) was called by ext. script1 (which in turn was called by one of those several html files) the cookie set by ext. script2 would have root permission. But it does not, it has permission starting from the dir of the html file that called the ext. script1
So now I need to know is there a way to trick the system in thinking the set cookie script was called from the root directory, although in actual fact it is not because I want it to be any html file from any dir. Until now the only thing that works is the solution I started out with namely replacing ext. script2 by an actual html file that opens and closes from within the root to set the root permission cookie. I find it hard to believe that there isn't a way around this.