iLTC Home
Bookmark iLTC!
iLTC Google Boards

Google Groups
Receive The Code in Email!



Categories

Perl
  • Perl Tutorials Beginners

    Javascript
  • Javascript Tutorials
  • Javascript Tutorials Beginners

    HTML
  • HTML Tutorials



  • I bookmarked this site...
    20,089

    iLoveTheCode.com
    Javascript > Javascript Tutorials How To Easy > Javascript Redirect

    Javascript Redirect



    To redirect using Javascript:

    location.replace("http://google.com");

    -We use Javascript's built-in location object.
    -We use Javascript's built-in replace method.
    -In quotation marks and parenthesis, we type the URL we want to load in the browser.


    You may have seen different Javascript redirects like:

    window.location.href="http://google.com";
    or
    window.location="http://google.com";

    The advantage our first example (location.replace) is that users can still back up in their browser*. The latter two examples break the back button on Windows IE. Users cannot leave the page by clicking it. Many search engines don't like this behaviour.

    Another consideration is that search engines may not like a javascript redirect no matter how we do it. Here's a simple perl solution:

    #!/usr/bin/perl

    print "Location: http://google.com\n\n";

    iLoveTheCode Perl Redirect Article.


    *The technical reason location.replace doesn't break the back button is because the in-between page doesn't get written to the browser's History, therefore, a click back skips the redirecting page. The other two redirect options DO write to the browser's History.


    Free Copy and Paste Javascript Code:

    <script type="text/javascript">
    <!--

    location.replace("http://google.com");
    //window.location.href="http://google.com"; Commented out //
    //window.location="http://google.com"; Commented out //

    -->
    </script>


    Resources:
    A nice offsite Redirect tutorial
    Sun Documentation of LOCATION object

    Italic Text in Javascript
    Bold Text in Javascript
    Status Bar in Javascript
    Change Fonts in Javascript
    Change Font Size in Javascript

    HTML Tags
    HTML Color Chart
    HTML Codes


    Click HERE to comment or discuss at iLoveTheCode GOOGLE Group
    Previous Article: Javascript Status Bar
    Next Article: Javascript Bold Text





    CSSCSS

    David McFarland

    New $23.09

    Bulletproof Web DesignBulletproof Web Design

    Dan Cederholm

    New $26.39

    CSS MasteryCSS Mastery

    Andy Budd, Simon C...

    New $23.09

    Struts 2 in ActionStruts 2 in Action

    Don Brown, Chad Da...

    New $29.69

    Head First HTML with CSS...Head First HTML with CSS & XHTML

    Eric Freeman, Elis...

    New $26.39

    jQuery in ActionjQuery in Action

    Bear Bibeault, Yeh...

    New $26.39

    Learning Web DesignLearning Web Design

    Jennifer Niederst ...

    New $29.69

    Dreamweaver CS3Dreamweaver CS3

    David McFarland

    New $29.69

    HTML, XHTML, and CSS, Si...HTML, XHTML, and CSS, Sixth Edition ...

    Elizabeth Castro

    New $23.09


    Of Interest:
  • OPEN and WRITE a Data File in Perl
  • Write a FOREACH LOOP in Perl
  • Renaming a File with Perl's RENAME Function
  • Matching at the Beginning and End
  • Javascript Status Bar
  • Javascript Pop - Use Pop to Remove Items from the End of an Array in Javascript
  • Mimic Typing from a Textfield in a Textarea with Javascript
  • If, Else If, and Else in Javascript
  • HTML Center
  • Make Text Bold Using HTML
  • HTML Tables
  • HTML Font Code

  • More Articles:
  • Write a WHILE LOOP in Perl, Carefully
  • Add to the Beginning of an Array with Unshift in Perl
  • If, Elsif, and Else in Perl
  • Matching with a Regular Expression, REGEX, in Perl
  • Javascript Alert
  • Javascript Change Font Size
  • onClick Javascript
  • Javascript Change Background Colors
  • Change a Form Field with Javascript
  • Create a Function in Javascript
  • Passing an Argument or Variable to a Javascript
  • Increment a Variable in Javascript
  • HTML Tables
  • HTML Color Codes
  • HTML Frames
  • Make Text Bold Using HTML

  • Search iLTC w/ Google





    Recent Articles

  • Javascript Focus Form Field
  • Javascript Lowercase Text
  • Javascript Uppercase Text
  • Javascript Superscript Text
  • Javascript Subscript Text
  • Make Text Blink Using Javascript
  • Make a String into a Link in Javascript
  • Javascript Italics Text
  • Javascript Bold Text
  • Javascript Redirect
  • HTML Frames
  • HTML Color Chart
  • HTML Link
  • Javascript Status Bar








  • Perl Programming - Javascript Programming - Maybe Some PHP - Free Scripts - ILoveTheCode
    All Content © 2006 iLoveTheCode.com


    Contact Chris | About this Site


    316,829
    Counter by iLoveTheCode.com


    Last Modified: Friday, 23-Jun-2006 07:23:15 EDT