SlideShare a Scribd company logo
Lecture 19
Using One Frame for Your
Main JavaScript Code
          As explained in the previous lecture, HTML offers a concept called frames that allows you to
divide the available space in a given window into multiple frames into which you can load different
documents.
When you are working with frames, it is sometimes useful to place all your JavaScript functions in one
frame that will not change so they are easily accessible to all frames at all times.
For example, if all the functions fn1 (), fn2 () are placed inside frame1 and frame 2 want to call function
fn1 (), frame 2 will use the following statement
          Parent.frame1.fn1 ()

Let us take an example:
Below is the code for frameset.html
<HTML>
<frameset cols="50%,50%">
         <frame name="lp" src="frame1.html">
         <frame name="rp" src="frame2.html">
</frameset>
</HTML>

Below is the code for frame1.html
<HTML>
<HEAD>
<TITLE> Frame 1</TITLE>
<script language="JavaScript">
          function fn1()
          {
                   window.alert("Function 1() called");
          }

         function fn2()
         {
                   window.alert("Function 2() called");
         }
</script>
</HEAD>
<BODY>
         This is frame 1 <br>
         <a href="#" onClick="fn1()"> Call First Function </a> <br>
         <a href="#" onClick="fn2()"> Call Second Function</a>
</BODY>
</HTML>

Below is the code for frame2.html
<HTML>
<HEAD>
<TITLE>Frame 2</TITLE>
<script language="JavaScript">

</script>
</HEAD>
<BODY>
This is frame 2 <br>
<a href="#" onClick="parent.lp.fn1()"> Call First Function </a> <br>
      <a href="#" onClick="parent.lp.fn2()"> Call Second Function</a>
</BODY>
</HTML>

Using a Hidden Frame for
Your JavaScript Code
                 Sometimes you want to use a “hidden” frame to store a document containing nothing and
only your JavaScript code.

<frameset cols=”0,50%,50%”>
        <frame …>
        <frame …>
        <frame …>
</frameset>

Let us take an example
Here is code.html
<HTML>
<HEAD>
<TITLE> Source code for all the frames</TITLE>
<script language="JavaScript">
          function fn1()
          {
                   window.alert("function f1() called");
          }

         function fn2()
         {
                  window.alert("function f2() called");
         }
</script>
</HEAD>
<BODY>
</BODY>
</HTML>

Here is the frameset.html
<HTML>
<frameset cols="0,50%,50%">
         <frame name="codeFrame" src="code.html">
         <frame name="lp" src="frame1.html">
         <frame name="rp" src="frame2.html">
</frameset>
</HTML>

Below is frame1.html
<HTML>
<HEAD>
<TITLE> Frame 1</TITLE>
</HEAD>
<BODY>
        This is frame 1 <br>
        <a href="#" onClick="parent.codeFrame.fn1()"> Call First Function </a> <br>
        <a href="#" onClick="parent.codeFrame.fn2()"> Call Second Function</a>
</BODY>
</HTML>

Below is frame2.html
<HTML>
<HEAD>
<TITLE>Frame 2</TITLE>
</HEAD>
<BODY>
This is frame 2 <br>
          <a href="#" onClick="parent.codeFrame.fn1()"> Call First Function </a> <br>
          <a href="#" onClick="parent.codeFrame.fn2()"> Call Second Function</a>
</BODY>
</HTML>

Working with Nested Frames
         All the examples that you have seen till now only deal with single layer frames. We can have
nesting of frames that mean, a frame can be further sub divided into two frames. How to use JavaScript
code with nested frames?

Here is an example to understand calling functions in Nested Frames

Below is the code for frameset.html
<HTML>
<frameset cols="50%,50%">
        <frame name="lp" src="frame1.html">
        <frame name="rp" src="frame2.html">
</frameset>
</HTML>

Below is the code for frame1.html
<HTML>
<HEAD>
<TITLE> Frame 1</TITLE>
</HEAD>
<BODY>
        This is frame 1 <br>
        <a href="#" onClick="parent.rp.subFrame2.fn1()"> Call Function in SubFrame 2 of Frame 2</a>
</BODY>
</HTML>
Below is the code for frame2.html
<HTML>
<frameset rows="20%,80%">
        <frame name="subFrame1" src="subFrame1.html">
        <frame name="subFrame2" src="subFrame2.html">
</frameset>
</HTML>
Below is the code for subFrame1.html
<HTML>
<HEAD>
<TITLE> Sub Frame1</TITLE>
</HEAD>
<BODY>
        This is sub Frame 1
</BODY>
</HTML>
Below is the code for subFrame2.html
<HTML>
<HEAD>
<TITLE> Sub Frame2 </TITLE>
<script language="JavaScript">
          function fn1()
          {
                    window.alert("Function f1 called");
          }
</script>
</HEAD>
<BODY>
          This is subFrame 2
</BODY>
</HTML>

Dynamically Creating Frames
in JavaScript
Dynamically creating frame means, creating the <frameset> and <frame> at runtime using JavaScript. Till
now, we have been creating <frameset> using HTML. But now we will learn, How to create <frameset> at
run time.

Here is the code for that.

<HTML>
<script language="JavaScript">
          document.open();
          document.write("<frameset cols='50%,50%'>");
                 document.write("<frame src='frame1.html' name='lp'>");
                 document.write("<frame src='frame2.html' name='rp'>");
          document.write("</frameset>");
          document.close();
</script>
</HTML>

Important thing that is worth mentioning here is that I have used single quotes (‘’) instead of (“”) in all the
tags.

More Related Content

PPTX
Test driven development (java script & mivascript)
Miva
 
PDF
2013-06-25 - HTML5 & JavaScript Security
Johannes Hoppe
 
PDF
Js c1 best practices
Ernesto Esparaquia
 
ODP
Os Leonard
oscon2007
 
PDF
Simplifying Code: Koombea TechTalks
Koombea
 
PDF
Rails and security
Andrey Tokarchuk
 
PPTX
Clean Code: Chapter 3 Function
Kent Huang
 
PPTX
Boot strap.groovy
Vijay Shukla
 
Test driven development (java script & mivascript)
Miva
 
2013-06-25 - HTML5 & JavaScript Security
Johannes Hoppe
 
Js c1 best practices
Ernesto Esparaquia
 
Os Leonard
oscon2007
 
Simplifying Code: Koombea TechTalks
Koombea
 
Rails and security
Andrey Tokarchuk
 
Clean Code: Chapter 3 Function
Kent Huang
 
Boot strap.groovy
Vijay Shukla
 

Similar to Java script advanced frame (20)

RTF
Java script frame window
H K
 
DOC
Html basics 8 frame
H K
 
PDF
Unit 2.10 - Frames
Intan Jameel
 
PPTX
Frames and its components
Deepam Aggarwal
 
PPTX
Final_Frames.pptx
SajalZawar
 
PPTX
Web topic 9 navigation and link
CK Yang
 
PPTX
Presentation1
shwetashinde58
 
DOCX
Html frames
Abhishek Kesharwani
 
PPTX
Html frames
nobel mujuji
 
PDF
Beyond 60fps
Chris Thoburn
 
PPT
Frames.ppt
anshchaudhary9988
 
PPTX
uptu web technology unit 2 html
Abhishek Kesharwani
 
DOC
Java script frame history
H K
 
PPTX
HTML FRAMES properties and list of frames in detail
22eg105n11
 
PDF
p032-26
tutorialsruby
 
PDF
p032-26
tutorialsruby
 
PDF
Java script tutorial by example
myzyzy
 
PPTX
Html Frames
Xainab Ishfaq
 
Java script frame window
H K
 
Html basics 8 frame
H K
 
Unit 2.10 - Frames
Intan Jameel
 
Frames and its components
Deepam Aggarwal
 
Final_Frames.pptx
SajalZawar
 
Web topic 9 navigation and link
CK Yang
 
Presentation1
shwetashinde58
 
Html frames
Abhishek Kesharwani
 
Html frames
nobel mujuji
 
Beyond 60fps
Chris Thoburn
 
Frames.ppt
anshchaudhary9988
 
uptu web technology unit 2 html
Abhishek Kesharwani
 
Java script frame history
H K
 
HTML FRAMES properties and list of frames in detail
22eg105n11
 
p032-26
tutorialsruby
 
p032-26
tutorialsruby
 
Java script tutorial by example
myzyzy
 
Html Frames
Xainab Ishfaq
 
Ad

More from H K (20)

PDF
Assignment4
H K
 
DOCX
Assignment3
H K
 
PDF
Induction
H K
 
PDF
Solution3
H K
 
PDF
Solution2
H K
 
DOCX
Mid-
H K
 
PDF
Assignment4
H K
 
PDF
Assignment4
H K
 
PDF
Dm assignment3
H K
 
PPT
Proof
H K
 
PDF
Resolution
H K
 
DOCX
Assignment description
H K
 
PDF
Dm assignment2
H K
 
PDF
Set
H K
 
PDF
Dm assignment1
H K
 
PPTX
Logic
H K
 
DOCX
Introduction
H K
 
PDF
Assignment 2 sol
H K
 
PDF
Assignment sw solution
H K
 
PDF
Violinphoenix
H K
 
Assignment4
H K
 
Assignment3
H K
 
Induction
H K
 
Solution3
H K
 
Solution2
H K
 
Mid-
H K
 
Assignment4
H K
 
Assignment4
H K
 
Dm assignment3
H K
 
Proof
H K
 
Resolution
H K
 
Assignment description
H K
 
Dm assignment2
H K
 
Set
H K
 
Dm assignment1
H K
 
Logic
H K
 
Introduction
H K
 
Assignment 2 sol
H K
 
Assignment sw solution
H K
 
Violinphoenix
H K
 
Ad

Recently uploaded (20)

PDF
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
PPTX
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
DOCX
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
PDF
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PPTX
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
Celine George
 
PPTX
Artificial-Intelligence-in-Drug-Discovery by R D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
DOCX
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PDF
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
PPTX
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PPTX
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
PDF
RA 12028_ARAL_Orientation_Day-2-Sessions_v2.pdf
Seven De Los Reyes
 
PPTX
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
PPTX
Care of patients with elImination deviation.pptx
AneetaSharma15
 
PDF
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
PPTX
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
PPT
Python Programming Unit II Control Statements.ppt
CUO VEERANAN VEERANAN
 
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
Celine George
 
Artificial-Intelligence-in-Drug-Discovery by R D Jawarkar.pptx
Rahul Jawarkar
 
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
RA 12028_ARAL_Orientation_Day-2-Sessions_v2.pdf
Seven De Los Reyes
 
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
Care of patients with elImination deviation.pptx
AneetaSharma15
 
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
Python Programming Unit II Control Statements.ppt
CUO VEERANAN VEERANAN
 

Java script advanced frame

  • 1. Lecture 19 Using One Frame for Your Main JavaScript Code As explained in the previous lecture, HTML offers a concept called frames that allows you to divide the available space in a given window into multiple frames into which you can load different documents. When you are working with frames, it is sometimes useful to place all your JavaScript functions in one frame that will not change so they are easily accessible to all frames at all times. For example, if all the functions fn1 (), fn2 () are placed inside frame1 and frame 2 want to call function fn1 (), frame 2 will use the following statement Parent.frame1.fn1 () Let us take an example: Below is the code for frameset.html <HTML> <frameset cols="50%,50%"> <frame name="lp" src="frame1.html"> <frame name="rp" src="frame2.html"> </frameset> </HTML> Below is the code for frame1.html <HTML> <HEAD> <TITLE> Frame 1</TITLE> <script language="JavaScript"> function fn1() { window.alert("Function 1() called"); } function fn2() { window.alert("Function 2() called"); } </script> </HEAD> <BODY> This is frame 1 <br> <a href="#" onClick="fn1()"> Call First Function </a> <br> <a href="#" onClick="fn2()"> Call Second Function</a> </BODY> </HTML> Below is the code for frame2.html <HTML> <HEAD> <TITLE>Frame 2</TITLE> <script language="JavaScript"> </script> </HEAD> <BODY> This is frame 2 <br>
  • 2. <a href="#" onClick="parent.lp.fn1()"> Call First Function </a> <br> <a href="#" onClick="parent.lp.fn2()"> Call Second Function</a> </BODY> </HTML> Using a Hidden Frame for Your JavaScript Code Sometimes you want to use a “hidden” frame to store a document containing nothing and only your JavaScript code. <frameset cols=”0,50%,50%”> <frame …> <frame …> <frame …> </frameset> Let us take an example Here is code.html <HTML> <HEAD> <TITLE> Source code for all the frames</TITLE> <script language="JavaScript"> function fn1() { window.alert("function f1() called"); } function fn2() { window.alert("function f2() called"); } </script> </HEAD> <BODY> </BODY> </HTML> Here is the frameset.html <HTML> <frameset cols="0,50%,50%"> <frame name="codeFrame" src="code.html"> <frame name="lp" src="frame1.html"> <frame name="rp" src="frame2.html"> </frameset> </HTML> Below is frame1.html <HTML> <HEAD> <TITLE> Frame 1</TITLE> </HEAD> <BODY> This is frame 1 <br> <a href="#" onClick="parent.codeFrame.fn1()"> Call First Function </a> <br> <a href="#" onClick="parent.codeFrame.fn2()"> Call Second Function</a> </BODY>
  • 3. </HTML> Below is frame2.html <HTML> <HEAD> <TITLE>Frame 2</TITLE> </HEAD> <BODY> This is frame 2 <br> <a href="#" onClick="parent.codeFrame.fn1()"> Call First Function </a> <br> <a href="#" onClick="parent.codeFrame.fn2()"> Call Second Function</a> </BODY> </HTML> Working with Nested Frames All the examples that you have seen till now only deal with single layer frames. We can have nesting of frames that mean, a frame can be further sub divided into two frames. How to use JavaScript code with nested frames? Here is an example to understand calling functions in Nested Frames Below is the code for frameset.html <HTML> <frameset cols="50%,50%"> <frame name="lp" src="frame1.html"> <frame name="rp" src="frame2.html"> </frameset> </HTML> Below is the code for frame1.html <HTML> <HEAD> <TITLE> Frame 1</TITLE> </HEAD> <BODY> This is frame 1 <br> <a href="#" onClick="parent.rp.subFrame2.fn1()"> Call Function in SubFrame 2 of Frame 2</a> </BODY> </HTML> Below is the code for frame2.html <HTML> <frameset rows="20%,80%"> <frame name="subFrame1" src="subFrame1.html"> <frame name="subFrame2" src="subFrame2.html"> </frameset> </HTML> Below is the code for subFrame1.html <HTML> <HEAD> <TITLE> Sub Frame1</TITLE> </HEAD> <BODY> This is sub Frame 1 </BODY> </HTML> Below is the code for subFrame2.html
  • 4. <HTML> <HEAD> <TITLE> Sub Frame2 </TITLE> <script language="JavaScript"> function fn1() { window.alert("Function f1 called"); } </script> </HEAD> <BODY> This is subFrame 2 </BODY> </HTML> Dynamically Creating Frames in JavaScript Dynamically creating frame means, creating the <frameset> and <frame> at runtime using JavaScript. Till now, we have been creating <frameset> using HTML. But now we will learn, How to create <frameset> at run time. Here is the code for that. <HTML> <script language="JavaScript"> document.open(); document.write("<frameset cols='50%,50%'>"); document.write("<frame src='frame1.html' name='lp'>"); document.write("<frame src='frame2.html' name='rp'>"); document.write("</frameset>"); document.close(); </script> </HTML> Important thing that is worth mentioning here is that I have used single quotes (‘’) instead of (“”) in all the tags.