Showing posts with label Java Script. Show all posts
Showing posts with label Java Script. Show all posts

opener property in Java Script

2 comments
Using "opener" property, we can access the main window from the newly opened window.

Let's create Main page:

<html>
<head>
<title>Main Page</title>
</head>
<body>
<form>
<input type="button" value="Open another page"
onClick="aa=window.open('test.htm','','width=100,height=200')">
</form>
</body>
</html>

Then create Remote control page (in this example, that is test.htm):
<html>
<head>
<title>Child Page</title>
<script>
function remote(url)
{
window.opener.location=url
}
</script>
</head>

<body>
<p><a href="#" onClick="remote('file1.htm')">File1</a></p>
<p><a href="#" onClick="remote('file2.htm')">File2</a></p>
</body>

</html>
Continue Reading...

Remote window

0 comments
<html>
<head>
<title>Remote window</title>
</head>
<body>
<form>
<input type="button" value="Open another page"
onclick="aa=window.open('test.htm','','width=200,height=200')">
<input type="radio" name="x" onclick="aa.document.bgColor='red'">
<input type="radio" name="x" onclick="aa.document.bgColor='green'">
<input type="radio" name="x" onclick="aa.document.bgColor='yellow'">
</form>
</body>
</html>
Continue Reading...

Loading

0 comments
  • The basic syntax when loading new content into a window is:
    window.location="test.htm"
  • This is the same as
    <a href="test.htm>Try this </a>
Continue Reading...

Close a Window

0 comments
  • Your can use one of the codes shown below:
    <form>
    <input type="button" value="Close Window" onClick="window.close()">
    </form>
  • This is the same as
    <a href="javascript:window.close()">Close Window</a>
Continue Reading...

reload method in Java Script

1 comments
To reload a window, use this method:
window.location.reload()
Continue Reading...

Attributes

0 comments
  •  Let's add some of attributes to the above script to control the size of the window, and show: toolbar, scrollbars etc. The syntax to add attributes is:
    open("URL","name","attributes")
  • Here is the complete list of attributes you can add:
    • width
    • height
    • toolbar
    • location
    • directories
    • status
    • scrollbars
    • resizable
    • menubar
  • For example:
    <form>
    <input type="button" value="Click here to see"
    onclick="window.open('page2.htm','win1','width=200,height=200,menubar')">
    </form>
Continue Reading...

To open a new window

0 comments
To open a window, simply use the method "window.open()":

<form>
<input type="button" value="Click here to see" onclick="window.open('test.htm')">
</form>
Continue Reading...

Dynamic Display

0 comments
var banTime= new Date()
var ss=banTime.getHours()
if (ss<=12)
document.write("<img src='banner1.gif'>")
else
document.write("<img src='banner2.gif'>")
Continue Reading...

Java Script example for display Date

0 comments
<HTML>

<HEAD>
<TITLE>
Show Date
</TITLE>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
var x= new Date();
document.write (x);
</SCRIPT>
</BODY>

</HTML>
Continue Reading...

Date Objects in Java Script

0 comments
Methods of Date object :
  • getDate
  • getTime
  • getTimezoneOffset
  • getDay
  • getMonth
  • getYear
  • getSeconds
  • getMinutes
  • getHours
Continue Reading...

onMouseOver function in Java Script

0 comments
<a href="#" onMouseOver="location='main.htm'">
Mouse over to see Main Page
</a>
Continue Reading...

onClick function in Java Script

0 comments
<a href="#" onClick="alert('Hello, world!')">
Click me to say Hello
</a><
Continue Reading...

Reload function in Java Script

0 comments
<a href="JavaScript:window.location.reload()">
Click to reload!
</a>
Continue Reading...

Protect a file in Java Script

0 comments
 Protect a file using Login ID and Password.

 <html>
<head>

<script language="JavaScript">
function checkLogin(x)
{
if ((x.id.value != "Sam")||(x.pass.value !="Sam123"))
{
alert("Invalid Login");
return false;
}
else
location="main.htm"
}
</script>

</head>
<body>
<form>
<p>
UserID:<input type="text" name="id"></p>
<p>
Password:<input type="password" name="pass"></p>
<p>
<input type="button" value="Login" onclick="checkLogin(this.form)"></p>
</form>
</body>
</html>
Continue Reading...
0 comments
  • This is a method of the text box, which basically forces the cursor to be at the specified text box. onsubmit Unlike onblur, onsubmit handler is inserted inside the <form> tag, and not inside any one element.
  • For example:

    <script>
    <!--
    function validate()
    {
    if(document.login.userName.value=="")
    {
    alert ("Please enter User Name")
    document.login.userName.focus()
    return false
    }
    if(document.login.password.value=="")
    {
    alert ("Please enter Password")
    document.login.password.focus()
    return false
    }
    }
    //-->
    </script>

    <form name="login" onsubmit="return validate()">
    Enter your name: <input name="userName" />

    Enter your Password: <input name="password" />

    <input name="submit" type="submit" /></form>
Continue Reading...

indexOf()

0 comments
What is: x.indexOf(@)==-1? This is a method that JavaScript can search every character within a string and look for what we want. If it finds it will return the position of the char within the string. If it doesn't, it will return -1. Therefore, x.indexOf("@")==-1 basically means: "if the string doesn't include @"
Continue Reading...

onBlur()

0 comments
  • If you want to get information from users and want to check each element (ie: user name, password, email) individually, and alert the user to correct the wrong input before moving on, you can use onBlur.
  • For example:

    <html>
    <head>
    <script>
    function emailchk()
    {
    var x=document.feedback.email.value
    if (x.indexOf("@")==-1)
    {
    alert("It seems you entered an invalid email address.")
    document.feedback.email.focus()
    }
    }
    </script>
    </head>
    <body>
    <form name="feedback">
    Email:
    <input type="text" size="20" name="email" onblur="emailchk()">
    <br>
    Comment:
    <textarea name="comment" rows="2" cols="20"></textarea>
    <br>
    <input type="submit" value="Submit">
    </form>
    </body>
    </html>
  • If you enter an email address without the @, you'll get an alert asking you to re-enter the data.
Continue Reading...

Multiple Actions in Java Script

0 comments
  • How do you have an event handler call multiple functions/statements?
  • That's simple. You just need to embed the functions inside the event handler as usual, but separate each of them using a semicolon:

    <form>
    <input type="button" value="Click here!" onClick="alert('Thanks for visiting my site!');
    window.location='http://www.yahoo.com'">
    </form>
Continue Reading...

onUnload event

0 comments
The onunload executes JavaScript while someone leaves the page. For example to thank users.

<body onunload="alert('Thank you for visiting us. See you soon')">
Continue Reading...

Mouse events in Java Script

0 comments
  • These handlers are used exclusively with links.
  • These are
    • onMouseOver()
    • onMouseOut()
  • For example:
    • <a href="#" onMouseOver="document.write('Hi, nice to see you!">Over Here!>/a>
    • <a href="#" onMouseOut="alert('Good try!')">Get Out Here!>/a>
Continue Reading...
> Related Posts with Thumbnails
 

Copyright © 2012. GS dot net - All Rights Reserved - Design by BTDesigner - Proudly powered by Blogger