3

I have a html code in which i had two javascripts. I want to call the function of 1 javascript into another. Below given is the structure of my javascript.

<html>
<head>
<script>
function a()
{
//function code
this.parent["asd"].b(); //problem in dis line 
}
</script>
<body>
<script>
var asd= new Asd();
function b()
{
//function code here
}
</script>
</body>
</html>

It works fine when i use it locally or from a web server. But if i upload this page in my facebook application, the parent class points somewhere else since its inside a iframe. How to resolve it. Is there any other way to call the function.

2
  • I think you are new with java script . Commented Sep 21, 2012 at 5:44
  • yes learning it for the past 1 month Commented Sep 21, 2012 at 5:59

6 Answers 6

4
+50

You can:

=> combine both javascripts which you want to use in one

or

=> include a file first of which function you want to use in another javascript so it will automaticall get the value from that javascript file.

Sign up to request clarification or add additional context in comments.

3 Comments

i am telling in genralized concept where we want to include two javascripts in our html or in view page...i think now i am making smwhat clear...
order of javascript doesn't matter if it is global function.
yes you are correct in global scenario but it matters if you are going to use library functions or any other function defined in one file and want to call in another file...
2

Its doesn't matter that you have written function in same script tag or in another it easily called with function name only like below

<html>
<head>
<script>
function a()
{
//function code
b(); //problem in dis line 
}
</script>
<body>
<script>
var asd= new Asd();
function b()
{
//function code here
}
</script>
</body>
</html>

3 Comments

But when i simply call it. Its not working. please visit the link der is my fb app praveen.comyr.com/fb
for which perticular section you are asking for
jsfiddle.net/UCBTG look at dis fiddle. In this if i call dis function next(); its not working bcos its inside some frame. Is there any other alternate way to call the next method without using parent class.
1

It is always better to combine all your Javascript files into one complete js file. So, you can just merge both your javascript files together. That would also save you from this trouble. You can also see this thread.

2 Comments

I tried combining but i failed. If possible please try it. here is the fiddle jsfiddle.net/UCBTG/1
What is the use of your "timer.js" file? I mean I need this file to work.
1

Can you try eval("asd").b(); instead of this.parent["asd"].b();

Comments

1

it doenst matter. you can call any function already refered in the HTML as in the same file. because ultimately everything in same page.

Comments

0

Thank u all. i got the solution. i removed the function word from the javascript. now its working fine.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.