• الصفحة الرئيسية
  • إتصل بنا
  • سياسة الخصوصية
Logo
  • الرئيسية
  • أفكار
  • صحة
  • معلومات
  • عجائب وغرائب
  • تكنولوجيا
الصفحة الرئيسية JavaScript Programming Guide What are the Different Ways to Redirect Page in JavaScript?

What are the Different Ways to Redirect Page in JavaScript?

الكاتب ahmed في 3:00 AM JavaScript Programming Guide

Different Ways to Redirect Page in JavaScript
When you click on a link or type the URL to go to one page but sometimes it may go to another page internally due to page redirection on that page. There may be several reasons to redirect to a new page from the original page. The reasons you may want redirection are to redirect from your old domain to new domain, to redirect visitors from mobile device to the mobile site, to redirect to the visitors from different countries to their respective country level domain URL and many more.You can use temporary or permanent redirection methods to redirect from on page to another page. The permanent redirection is server side redirection and temporary redirection in client side redirection.

Using JavaScript you can do client side redirection, however it is not preferred method for page redirection, a search engine may ignore JavaScript redirection. Do not use this feature to spam the search engine, if such you may band from search engine. Here are given different redirection methods and their purpose to redirect from one page to another page in JavaScript, you may use any one of them according to your circumstance.


Simple JavaScript Redirection to Another Page


1. Using window.location method: Use these scripts to the head section of your 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


1. Using onLoad method: Use these scripts in body tag to redirect to another page after '5' seconds.

<body onLoad="setTimeout(location.href='http://www.newpage.com', '5000')">


2. Using Redirect function: Use these scripts in the head section to redirect to another page after '5' seconds with redirection message.

<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')">


2. Using a function: Use these scripts in the head section to redirect to another page on load.

<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


1. Using a function: Use these scripts in the body section to redirect to another page on button click with passing the value of text box.

<body>
<form action="/search">
Enter your search text: <input type="text" id="searchtext" name="q">
&nbsp;<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>

Enter your search text:  



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?
شارك المقال :
Tweet
✚

مقالات ذات صلة

التالي
المشاركةالتالية
السابق
المشاركة السابقة

تحويل كودإخفاء محول الأكواد الإبتساماتإخفاء

شكرا لمشاركتنا رأيك
Subscribe to: Post Comments (Atom)
  • Facebook
  • twitter
  • googleplus
  • youtube
  • linkedin

الأكثر زيارة

  • What is Information ?
    Information  can be defined as data that has been processed into a form that is meaningful to the recipient and is of real or perceived valu...
  • What is Information Technology?
    Definitions of  Information technology  ( IT ) It is a branch of engineering dealing with the use of computers and telecommunications equipm...
  • بالصور الفائزة بمسابقة ملكة جمال مصر 2017
    بالصور الفائزة بمسابقة ملكة جمال مصر 2017
    بالصور الفائزة بمسابقة ملكة جمال مصر 2017 لن تصدق من هي فرح صدقي ↓↓  لمشاهدة الصور والخبر كامل اضغط هنا  ↓↓ رابط المو...
  • Interview Questions on Stack and Queue in Data Structure set-2
    1) The queue in which the insertion takes place in the first position after of last element is a ...... A. priority B. dequeue C. circular D...
  • List of Top 65 Search Engine Submission Add URLs.
    List of Top 65 Search Engine Submission Add URLs.
    To get your site on the top ranking on the search engine results, Your site or URL must be indexed by Search Engines. For that you have to s...
  • List of Best Keyword Research Tools for Better SEO
    List of Best Keyword Research Tools for Better SEO
    Everyone needs to do keyword research work for the site before starting search engine optimization work as the first and most essential tas...
  • What are the different types of scheduling methods?
    Process scheduling is one way for a processor to handle n processes , by scheduling the execution process. Each process is executed one by ...
  • Solved MCQ on Database Backup and Recovery in DBMS set-1
    1) Which of the following is not a recovery technique? A. Deferred update B. Immediate update C. Two-phase commit D. Recovery management 2)C...
  • Solved MCQ on Distributed Database Transaction Management set-4
    1) Commit and rollback are related to .......... A. data integrity B. data consistency C. data sharing D. data security 2) The transaction w...
  • Solved MCQ on Fundamental of DBMS set-10
    1) Which of the following is not a characteristic of a relational database model? A. Table B. Tree like structure C. Complex logical relatio...

الأقسام

  • Artificial Intelligence(AI)
  • Backlinking
  • Basic IT
  • Best List
  • Blogging Tips
  • C
  • C#
  • C++
  • Computer Architecture
  • Computer Fundamental
  • Computer Security
  • Computer/IT Officer Exam
  • CSS
  • Data Mining and Warehousing
  • Data Recovery Tools
  • Data Structure
  • Database Management System
  • E-commerce
  • E-government
  • Internet & Web Designing
  • IT Law
  • IT Tips and Tricks
  • IT Tutorials
  • Java
  • JavaScript
  • Keyword Research Tools
  • MIS
  • Multiple Choice Question (MCQ)
  • Networking
  • Online Earning
  • Online IT Jobs
  • Operating System
  • Oracle Forms and Reports
  • Programming Guide
  • Programming Language
  • SEO
  • Social Networking Sites
  • Software Download
  • Software Engineering
  • System Analysis and Design
  • Top List
  • VB.Net
  • صحة
  • عجائب وغرائب

الأرشيف

  • ►  2017 (4)
    • ►  November (3)
    • ►  October (1)
  • ►  2016 (5)
    • ►  April (5)
  • ►  2015 (87)
    • ►  August (1)
    • ►  July (8)
    • ►  June (13)
    • ►  May (2)
    • ►  April (2)
    • ►  March (4)
    • ►  February (20)
    • ►  January (37)
  • ▼  2014 (77)
    • ►  December (31)
    • ►  November (4)
    • ►  September (4)
    • ►  August (11)
    • ►  July (8)
    • ►  June (2)
    • ►  May (2)
    • ►  April (2)
    • ►  March (2)
    • ▼  February (7)
      • How to Create a Digital Clock in JavaScript?
      • What are the Different Ways to Redirect Page in Ja...
      • How to Detect Visitor's Browser Using JavaScript?
      • How to Create Pop Up Menus in Oracle Forms ?
      • How to Insert, Navigate and Delete Records in Orac...
      • How to Create LOV in Oracle Forms Using Wizard ?
      • How to Create Oracle Forms by Using Wizard ?
    • ►  January (4)
  • ►  2013 (132)
    • ►  December (11)
    • ►  November (6)
    • ►  October (4)
    • ►  September (6)
    • ►  August (16)
    • ►  July (9)
    • ►  June (9)
    • ►  May (12)
    • ►  April (13)
    • ►  March (23)
    • ►  February (6)
    • ►  January (17)
  • ►  2012 (59)
    • ►  December (15)
    • ►  November (20)
    • ►  October (21)
    • ►  September (3)

إنضم لنا

© 2017 أفكار جميع الحقوق محفوظة