/    Sign up×
Community /Pin to ProfileBookmark

execute a function from out a parent(different) file?

for example

in the index.html I read some cookies.

I make a function in the index file with these cookies.

on a sub.html file i want to execute a fuction that I made in the index.html

to post a comment
JavaScript

10 Comments(s)

Copy linkTweet thisAlerts:
@VirbatemMay 20.2004 — Not much information to work with.

if index opens a new window:

window.open("sub.html","","");

sub.html function is:

window.opener.functionName();

If sub is a frame within index:

parent.subFrameName.function();

If you load sub.html where index.html was then the index.html functions are all gone.

Dion...

[o]


[i]Originally posted by itsmadmax [/i]

[B]for example



in the index.html I read some cookies.



I make a function in the index file with these cookies.



on a sub.html file i want to execute a fuction that I made in the index.html [/B]
[/QUOTE]
Copy linkTweet thisAlerts:
@itsmadmaxauthorMay 20.2004 — in the index.html file I make a function that i want to use in every sub page because i do not want to type the same things there over and over again.

But the most important thing is that if 1 thing changes in the function I have to change it in all the sub pages.

see this and read after the script.

<script>

var fil = YouWrote;


function noaccesstore(){

if ( fil == 01 || fil == 02 || fil == 03 || fil == 04 || fil == 05 || fil == 06 || fil == 07 || fil == 08 || fil == 09 || fil == 41 || fil == 48 || fil == 45)

{

window.open("paggeentoegang.html", "example1", "width=270, height=80, left=50, top=60, menubar=no, status=no, toolbar=no, scrollbars=no, resizable=no");

window.open("paghoofdmenu.html","left");

}


function noaccesoffice(){

if (fil == 48 }

window.open("paggeentoegang.html", "example1", "width=270, height=80, left=50, top=60, menubar=no, status=no, toolbar=no, scrollbars=no, resizable=no");

window.open("paghoofdmenu.html","left");

}


function noaccesdepartment(){

if (fil == 45 }

window.open("paggeentoegang.html", "example1", "width=270, height=80, left=50, top=60, menubar=no, status=no, toolbar=no, scrollbars=no, resizable=no");

window.open("paghoofdmenu.html","left");

}

</script>


*****************************************************

in a subpage(s) i want to say:

noaccesoffice()

In and other subpage(s) i want to say

noaccesstore()
Copy linkTweet thisAlerts:
@VirbatemMay 20.2004 — What you want is usually simply:

window.opener.noaccesoffice();

but I have had trouble with this lately. I think some of the microsoft patches and fixed have stuffed it for me.

There is an easier method which does not require permissions or other javascript security integrated things:

create a file containing only javascript; the functions you have included. Save the file as common.js in the same folder as your HTML pages.

At the top of each sub html page have something like this:

<html>

<head>

<script language="javascript" src="common.js"></script>

</head>

I place it in the HEAD tags because any javascript here will be executed (or loaded) first)

This way you can create a suite of common functions or core functions which are very long and need attention constantly. You can now modify your javascripts in one file or your display html in another file.

Additional external .js files must be in their own tag:

<script language="javascript" src="common.js"></script>

<script language="javascript" src="special.js"></script>

<script language="javascript" src="navigation.js"></script>

you call the functions in each .js file as if they were written in the html page. This is because they are literally written into the top of the page by the src="" attribute.


Dion...

[o]



[i]Originally posted by itsmadmax [/i]

[B]in the index.html file I make a function that i want to use in every sub page because i do not want to type the same things there over and over again.



But the most important thing is that if 1 thing changes in the function I have to change it in all the sub pages.



see this and read after the script.



<script>

var fil = YouWrote;


function noaccesstore(){

if ( fil == 01 || fil == 02 || fil == 03 || fil == 04 || fil == 05 || fil == 06 || fil == 07 || fil == 08 || fil == 09 || fil == 41 || fil == 48 || fil == 45)

{

window.open("paggeentoegang.html", "example1", "width=270, height=80, left=50, top=60, menubar=no, status=no, toolbar=no, scrollbars=no, resizable=no");

window.open("paghoofdmenu.html","left");

}


function noaccesoffice(){

if (fil == 48 }

window.open("paggeentoegang.html", "example1", "width=270, height=80, left=50, top=60, menubar=no, status=no, toolbar=no, scrollbars=no, resizable=no");

window.open("paghoofdmenu.html","left");

}


function noaccesdepartment(){

if (fil == 45 }

window.open("paggeentoegang.html", "example1", "width=270, height=80, left=50, top=60, menubar=no, status=no, toolbar=no, scrollbars=no, resizable=no");

window.open("paghoofdmenu.html","left");

}

</script>



*****************************************************



in a subpage(s) i want to say:

noaccesoffice()



In and other subpage(s) i want to say

noaccesstore() [/B]
[/QUOTE]
Copy linkTweet thisAlerts:
@itsmadmaxauthorMay 20.2004 — ok i understand this but nothing seems to happen.

i did a test with a file code.js

in there i wrote these lines.

<script>

function test(){

window.open("open.txt")

}

</script>

nothing more and nothing less. I assume this is just a plain txt file with no other html stuff in it?


then i made a test.html

<html>

<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<meta name="generator" content="Adobe GoLive 5">
<title>Welcome to Adobe GoLive 5</title>
<script language="javascript" src="code.js"></script>

</head>


<script>

test();

</script>

<body bgcolor="#ffffff">
<p></p>
</body>


</html>



but it does not work ?
Copy linkTweet thisAlerts:
@VirbatemMay 20.2004 — Try something LESS... you have some html tags in there. ONLY javascript can exist in an external javascript file.

Remove the <script> and </script> tags. Only have:

function test(){

window.open("open.txt")

}


Dion...

[o]


[i]Originally posted by itsmadmax [/i]

[B]ok i understand this but nothing seems to happen.



i did a test with a file code.js

in there i wrote these lines.



<script>

function test(){

window.open("open.txt")

}

</script>



nothing more and nothing less. I assume this is just a plain txt file with no other html stuff in it?





then i made a test.html

<html>



<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<meta name="generator" content="Adobe GoLive 5">
<title>Welcome to Adobe GoLive 5</title>
<script language="javascript" src="code.js"></script>

</head>


<script>

test();

</script>

<body bgcolor="#ffffff">
<p></p>
</body>


</html>



but it does not work ? [/B][/QUOTE]
Copy linkTweet thisAlerts:
@itsmadmaxauthorMay 20.2004 — YESSSSSSSS that worked....for this little test lol

Your good in this !!

BUT it did not yet for the password and cookie test...

but thats a thing i am going to find out tomorrow....(i hope)

its midnight here in Amsterdam

So thnx for now ? and maybe some help tomorrow
Copy linkTweet thisAlerts:
@VirbatemMay 20.2004 — I'll be going to bed too cos it's 6am here in australia :-)

I've had a long night and had some fun too.

Dion...

[o]

[i]Originally posted by itsmadmax [/i]

[B]YESSSSSSSS that worked....for this little test lol

Your good in this !!



BUT it did not yet for the password and cookie test...



but thats a thing i am going to find out tomorrow....(i hope)



its midnight here in Amsterdam



So thnx for now ? and maybe some help tomorrow [/B]
[/QUOTE]
Copy linkTweet thisAlerts:
@itsmadmaxauthorMay 21.2004 — ok we are back in business ?

it works now BUT i can not get back.

let me explain.

I start in a.html

I make a link to b.html

In b.html I call a function in code.js (this function checks if they can proceed.

In case i have no acces it actually does the function and opens a nice window that says NO ACCESS. ?

In case I have access it does nothing ?

Normaly it should go on reading the lines below the function in b.html

Must I say something in code.js after defining the function that it should go back to b.html and read on?


here are the codes.

*****************************************************
a.html

<li><a href="b.html" target="left">Store</a>


*****************************************************
b.html

//here i check if they have acces

var fil = YouWrote;

noaccesstore();

// if they dont have access it opens a window ( IT DOES ? )

// if they have access it should proceed with this next line ( it does not ? )

<li><a href="javascript:void(0)" onclick="myBonoplevdatum()">Bonnen op datum</a>


*****************************************************
code.js

function noaccesstore(){

if ( fil == 01 || fil == 02 || fil == 03 || fil == 04 || fil == 05 || fil == 06 || fil == 07 || fil == 08 || fil == 09 )

window.open("paggeentoegang.html", "example1", "width=270, height=80, left=50, top=60, menubar=no, status=no, toolbar=no, scrollbars=no, resizable=no");

window.open("a.html","left");

}


thanks again?
Copy linkTweet thisAlerts:
@itsmadmaxauthorMay 21.2004 — i think i found it.

i missed some {

is it true that a function goes like this?

function myfunction()

{

if(statement) {action};

}

because on some websites i read

function myfunction()

{

if (statement)

action;

}
Copy linkTweet thisAlerts:
@fredmvMay 21.2004 — Both statements are perfectly valid. However, the latter will work fine simply because the first piece of code after the inital statement or control structure declaration will execute. Every subsequent statement after the first inital one will not be executed, however. For that, the curleybraces are [i]required[/i]. Some, though, even when only executing one statement, do prefer the use of the curleybraces for better code readability. I generally omit them when unnessecary, but that's merely my preference.
×

Success!

Help @itsmadmax spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...