SlideShare a Scribd company logo
Lecture 20
Referring to Unnamed
Frames Numerically
This is the last topic with using Frames in JavaScript. Like we did with Forms, same is
the case with Frames. If we don’t give any name to forms, then in JavaScript first form is
referred as forms [0], second form is referred as forms [1]. This is because; JavaScript
maintains an array of all the forms.
Similarly, if frames are unnamed, i.e. we don’t give any name to frames, then in
JavaScript first frame is referred as frames [0], second frame is referred as frames [1],
and so on.

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

Below is the code for frame1.hmtl
<HTML>
<HEAD>
<TITLE> Frame 1</TITLE>
<script language="JavaScript">
        function fn1()
        {
                window.alert("This is function in frame 1");
        }
</script>
</HEAD>
<BODY>
        This is frame 1 <br>
        <a href="#" onClick="parent.frames[1].fn1()"> Call Function in Frame2</a>
</BODY>
</HTML>

Below is the code for frame2.html
<HTML>
<HEAD>
<TITLE> Frame 2</TITLE>
<script language="JavaScript">
        function fn1()
        {
window.alert("This is function in frame 2");
        }
</script>
</HEAD>
<BODY>
        This is frame 2 <br>
        <a href="#" onClick="parent.frames[0].fn1()"> Call Function in Frame1</a>
</BODY>
</HTML>


History Object
History Object Properties

   •   Length: Returns the number of items in the current history list

History Object Methods

   •   Back(): Moves back n items in the history list
   •   Forward(): Moves forward n items in the history list
   •   Go(): Moves to item n in the history list

There are currently no History object events. This means you cannot associate any event
with the History object.

History object contains the list of URL’s that your browser has visited. In other words,
History object is an array of all URL’s visited so far with the current open browser.

Since History object is an array, so it must have a length property, which will give you
the number of URL visited so far.

 Generally, if you want to go back to the previous page, you click the back button in the
menu bar of your browser. And, in case you want to go back to the next page, you click
the forward button
Notice: When you open a browser, back and forward button both are disabled.

If you want, you can provide that buttons on your web page, so that user can move back
and forward using your buttons rather than using browser buttons.




There are three ways to implement back and forward buttons
1. Back and Forward Using History
   2. Back and Forward Buttons (Simple)
   3. Back and Forward Buttons Without History

Back and Forward Using History
      Now, we will understand How to code back and forward button using history.

Below is the code
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script LANGUAGE="JavaScript">
        function back()
        {
               history.go(-1);
        }

        function forward()
        {
               history.go(+1);
        }
</script>
</HEAD>

<BODY>
<FORM>
<INPUT TYPE="button" VALUE="<< Back" onClick="back()">
<INPUT TYPE="button" VALUE="Forward >>" onClick="forward()">
</FORM>
</BODY>
</HTML>

Back and Forward Button (Simplest Way)

<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script LANGUAGE="JavaScript">
        function back()
        {
               Location.href=”a.html”;
        }

       function forward()
       {
              Location.href=”b.html”
}
</script>
</HEAD>

<BODY>
<INPUT TYPE="button" VALUE="<< Back" onClick="back()">
<INPUT TYPE="button" VALUE="Forward >>" onClick="forward()">
</BODY>
</HTML>

Back and Forward buttons without using history object

<script language="JavaScript">

var MyLocation=window.location;

var MyPage=new Array;

{

       MyPage[0]="index.html";

       MyPage[1]="alerts.htm";

       MyPage[2]="alertsText.htm";

       MyPage[3]="alertsImages.htm";

       MyPage[4]="jumpfunction.htm";

       MyPage[5]="alertConfirm.htm";

       MyPage[6]="alertConfirm2Locs.htm";

       MyPage[7]="alertOnLoad.htm";

       MyPage[8]="alertHelloEx.htm";

       MyPage[9]="alertPrompts.htm";

       MyPage[10]="documentWrite.htm";

       MyPage[11]="documentWrite2.htm";
MyPage[12]="WindowNew.htm";

      MyPage[13]="WindowNew2.htm";

      MyPage[14]="WindowNewHyperlinks.htm";

      MyPage[15]="menu1.htm";

      MyPage[16]="menuSelectOnChange.htm";

      MyPage[17]="ArrayText.htm";

      MyPage[18]="jsFrames.htm";

      MyPage[19]="frameHyperlinks.htm";

      MyPage[20]="BackForward.htm"; }

function GoBack() {

if (ThisPageNumber <=0) {

alert("You are at the beginning of this series");

}

else{ ThisPageNumber=ThisPageNumber-1;

window.location=MyPage[ThisPageNumber];

}}

function GoForward(){

ThisPageNumber=ThisPageNumber+1;

if (ThisPageNumber >=MyPage.length) {

answer=confirm("You are at the end of the present series. "+

"Press ok to go to the beginning. Cancel to stay here");

if (answer!=0) {
ThisPageNumber=0; window.location=MyPage[ThisPageNumber]; }
ThisPageNumber=ThisPageNumber-1;

}

else {

window.location=MyPage[ThisPageNumber];

}

}

</script>

More Related Content

What's hot (20)

Javascript Experiment
Javascript Experiment
wgamboa
 
5. CodeIgniter copy1
5. CodeIgniter copy1
Razvan Raducanu, PhD
 
Asp 3-html helpers in asp.net
Asp 3-html helpers in asp.net
Fajar Baskoro
 
13. view data
13. view data
Razvan Raducanu, PhD
 
Jqeury ajax plugins
Jqeury ajax plugins
Inbal Geffen
 
Borrar
Borrar
ilian patricia bocanegra alfaro
 
Lesson 202 02 oct13-1800-ay
Lesson 202 02 oct13-1800-ay
Codecademy Ren
 
UIWebView Tips
UIWebView Tips
Katsumi Kishikawa
 
Url&doc html
Url&doc html
akila m
 
Intro to DTCoreText: Moving Past UIWebView | iOS Development
Intro to DTCoreText: Moving Past UIWebView | iOS Development
SmartLogic
 
5. hello popescu
5. hello popescu
Razvan Raducanu, PhD
 
XPages Extension Library - Create an app in 1 hour (almost)
XPages Extension Library - Create an app in 1 hour (almost)
Per Henrik Lausten
 
jQuery basics for Beginners
jQuery basics for Beginners
Pooja Saxena
 
Java script
Java script
Gourishankar R Pujar
 
symfony & jQuery (phpDay)
symfony & jQuery (phpDay)
Massimiliano Arione
 
Laravel the right way
Laravel the right way
Matheus Marabesi
 
Broadleaf Presents Thymeleaf
Broadleaf Presents Thymeleaf
Broadleaf Commerce
 
HTML Forms
HTML Forms
bismakhan12
 
Advanced Interfaces and Repositories in Laravel
Advanced Interfaces and Repositories in Laravel
Jonathan Behr
 
CGI::Prototype (NPW 2006)
CGI::Prototype (NPW 2006)
brian d foy
 

Similar to Java script frame history (20)

Java script frame window
Java script frame window
H K
 
Introduction to Html5
Introduction to Html5
www.netgains.org
 
jQuery
jQuery
PumoTechnovation
 
Javascript 2
Javascript 2
pavishkumarsingh
 
Devoxx 2014-webComponents
Devoxx 2014-webComponents
Cyril Balit
 
lect4
lect4
tutorialsruby
 
lect4
lect4
tutorialsruby
 
Unit5_Web_Updvvgxsvjbffcvvgbjifszated.pptx
Unit5_Web_Updvvgxsvjbffcvvgbjifszated.pptx
1si23bt001
 
lec 14-15 Jquery_All About J-query_.pptx
lec 14-15 Jquery_All About J-query_.pptx
MuhammadAbubakar114879
 
Client Web
Client Web
Markiyan Matsekh
 
Unit3.pptx
Unit3.pptx
AnamikaRai59
 
Wt unit 5
Wt unit 5
team11vgnt
 
Introduction to jQuery
Introduction to jQuery
Seble Nigussie
 
Nagios Conference 2014 - Troy Lea - JavaScript and jQuery - Nagios XI Tips, T...
Nagios Conference 2014 - Troy Lea - JavaScript and jQuery - Nagios XI Tips, T...
Nagios
 
Unit – II (1).pptx
Unit – II (1).pptx
DrDhivyaaCRAssistant
 
J query training
J query training
FIS - Fidelity Information Services
 
Html5 For Jjugccc2009fall
Html5 For Jjugccc2009fall
Shumpei Shiraishi
 
Django crush course
Django crush course
Mohammed El Rafie Tarabay
 
Jquery
Jquery
Gulbir Chaudhary
 
HTML5 New and Improved
HTML5 New and Improved
Timothy Fisher
 
Ad

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)

Overview of Employee in Odoo 18 - Odoo Slides
Overview of Employee in Odoo 18 - Odoo Slides
Celine George
 
Revista digital preescolar en transformación
Revista digital preescolar en transformación
guerragallardo26
 
Sustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive Learning
Leonel Morgado
 
What is FIle and explanation of text files.pptx
What is FIle and explanation of text files.pptx
Ramakrishna Reddy Bijjam
 
PEST OF WHEAT SORGHUM BAJRA and MINOR MILLETS.pptx
PEST OF WHEAT SORGHUM BAJRA and MINOR MILLETS.pptx
Arshad Shaikh
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024
BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024
Quiz Club of PSG College of Arts & Science
 
Overview of Off Boarding in Odoo 18 Employees
Overview of Off Boarding in Odoo 18 Employees
Celine George
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
Chalukyas of Gujrat, Solanki Dynasty NEP.pptx
Chalukyas of Gujrat, Solanki Dynasty NEP.pptx
Dr. Ravi Shankar Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
Belicia R.S
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Dr. Ravi Shankar Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
LDMMIA GRAD Student Check-in Orientation Sampler
LDMMIA GRAD Student Check-in Orientation Sampler
LDM & Mia eStudios
 
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Rajdeep Bavaliya
 
IDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptx
ArneeAgligar
 
Allomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdf
Abha Pandey
 
Introduction to Generative AI and Copilot.pdf
Introduction to Generative AI and Copilot.pdf
TechSoup
 
Overview of Employee in Odoo 18 - Odoo Slides
Overview of Employee in Odoo 18 - Odoo Slides
Celine George
 
Revista digital preescolar en transformación
Revista digital preescolar en transformación
guerragallardo26
 
Sustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive Learning
Leonel Morgado
 
What is FIle and explanation of text files.pptx
What is FIle and explanation of text files.pptx
Ramakrishna Reddy Bijjam
 
PEST OF WHEAT SORGHUM BAJRA and MINOR MILLETS.pptx
PEST OF WHEAT SORGHUM BAJRA and MINOR MILLETS.pptx
Arshad Shaikh
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
Overview of Off Boarding in Odoo 18 Employees
Overview of Off Boarding in Odoo 18 Employees
Celine George
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
Belicia R.S
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
LDMMIA GRAD Student Check-in Orientation Sampler
LDMMIA GRAD Student Check-in Orientation Sampler
LDM & Mia eStudios
 
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Rajdeep Bavaliya
 
IDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptx
ArneeAgligar
 
Allomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdf
Abha Pandey
 
Introduction to Generative AI and Copilot.pdf
Introduction to Generative AI and Copilot.pdf
TechSoup
 

Java script frame history

  • 1. Lecture 20 Referring to Unnamed Frames Numerically This is the last topic with using Frames in JavaScript. Like we did with Forms, same is the case with Frames. If we don’t give any name to forms, then in JavaScript first form is referred as forms [0], second form is referred as forms [1]. This is because; JavaScript maintains an array of all the forms. Similarly, if frames are unnamed, i.e. we don’t give any name to frames, then in JavaScript first frame is referred as frames [0], second frame is referred as frames [1], and so on. Let us take an example. Below is the code for frameset.html <HTML> <frameset cols="50%,50%"> <frame src="frame1.html"> <frame src="frame2.html"> </frameset> </HTML> Below is the code for frame1.hmtl <HTML> <HEAD> <TITLE> Frame 1</TITLE> <script language="JavaScript"> function fn1() { window.alert("This is function in frame 1"); } </script> </HEAD> <BODY> This is frame 1 <br> <a href="#" onClick="parent.frames[1].fn1()"> Call Function in Frame2</a> </BODY> </HTML> Below is the code for frame2.html <HTML> <HEAD> <TITLE> Frame 2</TITLE> <script language="JavaScript"> function fn1() {
  • 2. window.alert("This is function in frame 2"); } </script> </HEAD> <BODY> This is frame 2 <br> <a href="#" onClick="parent.frames[0].fn1()"> Call Function in Frame1</a> </BODY> </HTML> History Object History Object Properties • Length: Returns the number of items in the current history list History Object Methods • Back(): Moves back n items in the history list • Forward(): Moves forward n items in the history list • Go(): Moves to item n in the history list There are currently no History object events. This means you cannot associate any event with the History object. History object contains the list of URL’s that your browser has visited. In other words, History object is an array of all URL’s visited so far with the current open browser. Since History object is an array, so it must have a length property, which will give you the number of URL visited so far. Generally, if you want to go back to the previous page, you click the back button in the menu bar of your browser. And, in case you want to go back to the next page, you click the forward button Notice: When you open a browser, back and forward button both are disabled. If you want, you can provide that buttons on your web page, so that user can move back and forward using your buttons rather than using browser buttons. There are three ways to implement back and forward buttons
  • 3. 1. Back and Forward Using History 2. Back and Forward Buttons (Simple) 3. Back and Forward Buttons Without History Back and Forward Using History Now, we will understand How to code back and forward button using history. Below is the code <HTML> <HEAD> <TITLE> New Document </TITLE> <script LANGUAGE="JavaScript"> function back() { history.go(-1); } function forward() { history.go(+1); } </script> </HEAD> <BODY> <FORM> <INPUT TYPE="button" VALUE="<< Back" onClick="back()"> <INPUT TYPE="button" VALUE="Forward >>" onClick="forward()"> </FORM> </BODY> </HTML> Back and Forward Button (Simplest Way) <HTML> <HEAD> <TITLE> New Document </TITLE> <script LANGUAGE="JavaScript"> function back() { Location.href=”a.html”; } function forward() { Location.href=”b.html”
  • 4. } </script> </HEAD> <BODY> <INPUT TYPE="button" VALUE="<< Back" onClick="back()"> <INPUT TYPE="button" VALUE="Forward >>" onClick="forward()"> </BODY> </HTML> Back and Forward buttons without using history object <script language="JavaScript"> var MyLocation=window.location; var MyPage=new Array; { MyPage[0]="index.html"; MyPage[1]="alerts.htm"; MyPage[2]="alertsText.htm"; MyPage[3]="alertsImages.htm"; MyPage[4]="jumpfunction.htm"; MyPage[5]="alertConfirm.htm"; MyPage[6]="alertConfirm2Locs.htm"; MyPage[7]="alertOnLoad.htm"; MyPage[8]="alertHelloEx.htm"; MyPage[9]="alertPrompts.htm"; MyPage[10]="documentWrite.htm"; MyPage[11]="documentWrite2.htm";
  • 5. MyPage[12]="WindowNew.htm"; MyPage[13]="WindowNew2.htm"; MyPage[14]="WindowNewHyperlinks.htm"; MyPage[15]="menu1.htm"; MyPage[16]="menuSelectOnChange.htm"; MyPage[17]="ArrayText.htm"; MyPage[18]="jsFrames.htm"; MyPage[19]="frameHyperlinks.htm"; MyPage[20]="BackForward.htm"; } function GoBack() { if (ThisPageNumber <=0) { alert("You are at the beginning of this series"); } else{ ThisPageNumber=ThisPageNumber-1; window.location=MyPage[ThisPageNumber]; }} function GoForward(){ ThisPageNumber=ThisPageNumber+1; if (ThisPageNumber >=MyPage.length) { answer=confirm("You are at the end of the present series. "+ "Press ok to go to the beginning. Cancel to stay here"); if (answer!=0) {