Simple JavaScript Redirection to Another Page
<script type="text/javascript">
window.location="http://www.newpage.com";
</script>
2. Using window.location.href method: Use these scripts to the head section of your page.
<script type="text/javascript">
window.location.href="http://www.newpage.com";
</script>
3. Using window.location.assign method: Use these scripts to the head section of your page.
<script type="text/javascript">
window.location.assign="http://www.newpage.com";
</script>
4. Using window.location.replace method: Use these scripts to the head section of your page.
<script type="text/javascript">
window.location.replace="http://www.newpage.com";
</script>
JavaScript Redirect to Another Page After 'x' Seconds
<body onLoad="setTimeout(location.href='http://www.newpage.com', '5000')">
<script type="text/javascript">
function Redirect()
{
window.location="http://www.newpage.com";
}
document.write("You will be redirected to a new page in 5 seconds");
setTimeout('Redirect()', 5000);
</script>
JavaScript Redirect to Another Page On Load
1. Using onLoad method: Use these scripts in body tag to redirect to another page on load.
<body onLoad="setTimeout(location.href='http://www.newpage.com', '0')">
<script type="text/javascript">
function Redirect()
{
window.location="http://www.newpage.com";
}
setTimeout('Redirect()', 0);
</script>
JavaScript Redirect to Another Page On Click
1. Using a function: Use these scripts in the head and body section to redirect to another page on button click.
<head>
<script>
function myButton()
{
window.location="http://www.siteforinfotech.com";
}
</script>
</head>
<body>
<button onclick="myButton()">Click me</button>
</body>
JavaScript Redirect to Another Page Passing Variables
<body>
<form action="/search">
Enter your search text: <input type="text" id="searchtext" name="q">
<input onclick="myFunction()" type="submit" value="Search It" /></form>
<script>
function myFunction()
{
var search = document.getElementById("searchtext").value;
window.location = '/search?q='+search;
}
</script>
</body>
Related Posts
- How to Detect Visitor's Browser Using JavaScript?
- How To Create Simple Image Slideshow Using JavaScript ?
- How to Create Simple JavaScript Fade Effect Animation?
- Image Slideshow with Navigation Buttons Using Javascript
- How to Create JavaScript Image Slideshow with Links
- Simple JavaScript Fade Effect Animation Using Jquery
- How to Create Simple JavaScript Fade Effect Animation?
إرسال تعليق
Click to see the code!
To insert emoticon you must added at least one space before the code.