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.
Ad

Recommended

Test driven development (java script & mivascript)
Test driven development (java script & mivascript)
Miva
 
2013-06-25 - HTML5 & JavaScript Security
2013-06-25 - HTML5 & JavaScript Security
Johannes Hoppe
 
Js c1 best practices
Js c1 best practices
Ernesto Esparaquia
 
Os Leonard
Os Leonard
oscon2007
 
Simplifying Code: Koombea TechTalks
Simplifying Code: Koombea TechTalks
Koombea
 
Rails and security
Rails and security
Andrey Tokarchuk
 
Clean Code: Chapter 3 Function
Clean Code: Chapter 3 Function
Kent Huang
 
Boot strap.groovy
Boot strap.groovy
Vijay Shukla
 
Java script frame window
Java script frame window
H K
 
Html basics 8 frame
Html basics 8 frame
H K
 
Unit 2.10 - Frames
Unit 2.10 - Frames
Intan Jameel
 
Frames and its components
Frames and its components
Deepam Aggarwal
 
Final_Frames.pptx
Final_Frames.pptx
SajalZawar
 
Html5
Html5
Abhishek Kesharwani
 
Html5
Html5
Abhishek Kesharwani
 
Web topic 9 navigation and link
Web topic 9 navigation and link
CK Yang
 
Presentation1
Presentation1
shwetashinde58
 
Html frames
Html frames
Abhishek Kesharwani
 
Html frames
Html frames
nobel mujuji
 
Beyond 60fps
Beyond 60fps
Chris Thoburn
 
Frames.ppt
Frames.ppt
anshchaudhary9988
 
uptu web technology unit 2 html
uptu web technology unit 2 html
Abhishek Kesharwani
 
Java script frame history
Java script frame history
H K
 
HTML FRAMES properties and list of frames in detail
HTML FRAMES properties and list of frames in detail
22eg105n11
 
p032-26
p032-26
tutorialsruby
 
p032-26
p032-26
tutorialsruby
 
Java script tutorial by example
Java script tutorial by example
myzyzy
 
Html Frames
Html Frames
Xainab Ishfaq
 
Assignment4
Assignment4
H K
 
Assignment3
Assignment3
H K
 

More Related Content

Similar to Java script advanced frame (20)

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

More from H K (20)

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

Recently uploaded (20)

List View Components in Odoo 18 - Odoo Slides
List View Components in Odoo 18 - Odoo Slides
Celine George
 
How to Manage Different Customer Addresses in Odoo 18 Accounting
How to Manage Different Customer Addresses in Odoo 18 Accounting
Celine George
 
Q1_ENGLISH_PPT_WEEK 1 power point grade 3 Quarter 1 week 1
Q1_ENGLISH_PPT_WEEK 1 power point grade 3 Quarter 1 week 1
jutaydeonne
 
Filipino 9 Maikling Kwento Ang Ama Panitikang Asiyano
Filipino 9 Maikling Kwento Ang Ama Panitikang Asiyano
sumadsadjelly121997
 
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
Kweku Zurek
 
LAZY SUNDAY QUIZ "A GENERAL QUIZ" JUNE 2025 SMC QUIZ CLUB, SILCHAR MEDICAL CO...
LAZY SUNDAY QUIZ "A GENERAL QUIZ" JUNE 2025 SMC QUIZ CLUB, SILCHAR MEDICAL CO...
Ultimatewinner0342
 
VCE Literature Section A Exam Response Guide
VCE Literature Section A Exam Response Guide
jpinnuck
 
SCHIZOPHRENIA OTHER PSYCHOTIC DISORDER LIKE Persistent delusion/Capgras syndr...
SCHIZOPHRENIA OTHER PSYCHOTIC DISORDER LIKE Persistent delusion/Capgras syndr...
parmarjuli1412
 
Peer Teaching Observations During School Internship
Peer Teaching Observations During School Internship
AjayaMohanty7
 
Gladiolous Cultivation practices by AKL.pdf
Gladiolous Cultivation practices by AKL.pdf
kushallamichhame
 
Values Education 10 Quarter 1 Module .pptx
Values Education 10 Quarter 1 Module .pptx
JBPafin
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 6-14-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 6-14-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
K12 Tableau User Group virtual event June 18, 2025
K12 Tableau User Group virtual event June 18, 2025
dogden2
 
How to use search fetch method in Odoo 18
How to use search fetch method in Odoo 18
Celine George
 
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Rajdeep Bavaliya
 
LDMMIA Yoga S10 Free Workshop Grad Level
LDMMIA Yoga S10 Free Workshop Grad Level
LDM & Mia eStudios
 
IIT KGP Quiz Week 2024 Sports Quiz (Prelims + Finals)
IIT KGP Quiz Week 2024 Sports Quiz (Prelims + Finals)
IIT Kharagpur Quiz Club
 
A Visual Introduction to the Prophet Jeremiah
A Visual Introduction to the Prophet Jeremiah
Steve Thomason
 
Hurricane Helene Application Documents Checklists
Hurricane Helene Application Documents Checklists
Mebane Rash
 
ECONOMICS, DISASTER MANAGEMENT, ROAD SAFETY - STUDY MATERIAL [10TH]
ECONOMICS, DISASTER MANAGEMENT, ROAD SAFETY - STUDY MATERIAL [10TH]
SHERAZ AHMAD LONE
 
List View Components in Odoo 18 - Odoo Slides
List View Components in Odoo 18 - Odoo Slides
Celine George
 
How to Manage Different Customer Addresses in Odoo 18 Accounting
How to Manage Different Customer Addresses in Odoo 18 Accounting
Celine George
 
Q1_ENGLISH_PPT_WEEK 1 power point grade 3 Quarter 1 week 1
Q1_ENGLISH_PPT_WEEK 1 power point grade 3 Quarter 1 week 1
jutaydeonne
 
Filipino 9 Maikling Kwento Ang Ama Panitikang Asiyano
Filipino 9 Maikling Kwento Ang Ama Panitikang Asiyano
sumadsadjelly121997
 
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
Kweku Zurek
 
LAZY SUNDAY QUIZ "A GENERAL QUIZ" JUNE 2025 SMC QUIZ CLUB, SILCHAR MEDICAL CO...
LAZY SUNDAY QUIZ "A GENERAL QUIZ" JUNE 2025 SMC QUIZ CLUB, SILCHAR MEDICAL CO...
Ultimatewinner0342
 
VCE Literature Section A Exam Response Guide
VCE Literature Section A Exam Response Guide
jpinnuck
 
SCHIZOPHRENIA OTHER PSYCHOTIC DISORDER LIKE Persistent delusion/Capgras syndr...
SCHIZOPHRENIA OTHER PSYCHOTIC DISORDER LIKE Persistent delusion/Capgras syndr...
parmarjuli1412
 
Peer Teaching Observations During School Internship
Peer Teaching Observations During School Internship
AjayaMohanty7
 
Gladiolous Cultivation practices by AKL.pdf
Gladiolous Cultivation practices by AKL.pdf
kushallamichhame
 
Values Education 10 Quarter 1 Module .pptx
Values Education 10 Quarter 1 Module .pptx
JBPafin
 
K12 Tableau User Group virtual event June 18, 2025
K12 Tableau User Group virtual event June 18, 2025
dogden2
 
How to use search fetch method in Odoo 18
How to use search fetch method in Odoo 18
Celine George
 
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Rajdeep Bavaliya
 
LDMMIA Yoga S10 Free Workshop Grad Level
LDMMIA Yoga S10 Free Workshop Grad Level
LDM & Mia eStudios
 
IIT KGP Quiz Week 2024 Sports Quiz (Prelims + Finals)
IIT KGP Quiz Week 2024 Sports Quiz (Prelims + Finals)
IIT Kharagpur Quiz Club
 
A Visual Introduction to the Prophet Jeremiah
A Visual Introduction to the Prophet Jeremiah
Steve Thomason
 
Hurricane Helene Application Documents Checklists
Hurricane Helene Application Documents Checklists
Mebane Rash
 
ECONOMICS, DISASTER MANAGEMENT, ROAD SAFETY - STUDY MATERIAL [10TH]
ECONOMICS, DISASTER MANAGEMENT, ROAD SAFETY - STUDY MATERIAL [10TH]
SHERAZ AHMAD LONE
 
Ad

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.