Wednesday, 14 August 2013

iframe how to use parent javascript file in iframe

iframe how to use parent javascript file in iframe

I am having two html file Parent.html & Child.html. Parent.html imports
jquery.js file and Child.html in iframe.
Parent.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="js/jquery.js"></script>
<script>
$('body').click(function() {
alert("asdgaskdj");
});
</script>
</head>
<body>
<!--Parent do some thing-->
<iframe id="workspace" style="width:100%;height:100%;overflow:auto;"
src="Child.html">
</iframe>
</body>
</html>
Child.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script>
$('body').click(function() {
alert("asdgaskdj");
});
</script>
</head>
<body>
<!--child do some thing-->
</body>
</html>
My qustion is already jquery has been imported by Parent.html Should i
import it again in Child.html
if i dont import in Child.html it shows $ is undefined.
Parent.html already imported 255KB of js file. Child.html also want to do
the same. If it does then again 255kb of file has to be downloaded from
the server. Is any other way to reach the solution.
Plz HELP !!!!!

No comments:

Post a Comment