Nov 8, 2009

Url Redirection = Javascript+html - Redirect using scripts!

free web hosting
Open Discussion > MODERATED AREA > Computers > Programming Languages > HTML, XML etc..

Url Redirection = Javascript+html - Redirect using scripts!

AlanDS
In javascript Browser redirection can be done in 3 ways:

1) Alert Redirect:
CODE
<html>
<script>
    alert("This page has been moved to a new location... click OK to be redirected.");
    location = "http://www.your-website.com";
</script>
</html>



2) Confirm and Redirect:
CODE
<html>
<script>
    if(confirm("This page has been moved to a new location... would you like to be redirected"))
    {
  location = "http://www.your-website.com";
    }
    else
    {
  history.back();
    }
</script>
</html>


3) Stealth Redirect:
CODE
<html>
<script>
    location = "http://www.your-website.com";
</script>
</html>

 

 

 


Comment/Reply (w/o sign-up)

WindAndWater
Browser redirection can also be accomplished through the use of META tags in HTML or through a specific clause in your .htaccess file.

html:
CODE
<META HTTP-EQUIV="refresh" CONTENT="5;URL=http://www.google.com">
will change the page to www.google.com after 5 seconds. Remember that meta tags go within your <head></head> tags.

.htaccess:
CODE
Redirect /site.html http://www.othersite.com/index.html


Whenever it's possible, it's best to use an alterative to javascript, as not all users will have it enabled.

Comment/Reply (w/o sign-up)

AlanDS
Will you please elaborate on how .htaccess is to be used.

Thanks

Comment/Reply (w/o sign-up)

WindAndWater
For some strange reason I can't seem to get redirect to work on my trap17 hosting; my guess is that we don't have mod_rewrite enabled. However, RedirectMatch (allows redirection with regEx matching for the pages) seems to work.

CODE
RedirectMatch permanent fromPage.html http://www.domain.com/toPage.html

"permanent" tells the browser that the redirection is permanent, but doesn't really affect much -- you can remove it if you want. The second page shouldn't have to use an absolute path, but for some reason it doesn't work on my trap17 account unless I do. To use it, simply copy the code snippit into a text editor, switch out the dummy names with real ones, and then save it as a plain-text file named ".htaccess". Once you're done, upload the file to whichever directory the file you want to be redirected is from. Alternatively, you can have your .htaccess file a few directories up (say in your root directory) and just specify the file by including the path.

Trap17 already has a .htaccess file for your www/public_html directory, so if you want to stick your redirection code there, just append it to the other file.

 

 

 


Comment/Reply (w/o sign-up)

AlanDS
Thanks for elaborating.

Comment/Reply (w/o sign-up)



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : url, redirection, javascript, html, redirect, scripts

  1. How To Redirect
    Not as simple as it sounds (5)
  2. Redirect Problem
    (6)
    Hi, does anyone know if there is a way to display say www.b.com at www.a.com without using redirect
    from a to b. The real problem i have is if you try going to www.frusciante.net you will get
    redirected to www.locborg.de/fru where the files are stored. The code in frusciante.net is: HTML
    FRAMESET border=0 frameSpacing=0 rows=100%,* frameBorder=0 > FRAME name=bannerframe src ="
    http://www.locborg.de/fru/ " noResize> /FRAMESET > So is there a way to display the files from
    locborg.de/fru while maintaining the frusciante.net URL in the browser?....
  3. 301 Redirect And Bots
    a small doubt (6)
    Hi guys, I am presently developing a website which depends on JavaScript for its design. The
    problem is that some browsers do not JavaScript enabled. So, in case Script cannot be run on the
    browser, I have given a 301 (Meta) Redirect to a page which will tell them to enable the script.
    What about the Search engine bots? Will they undergo the 301 Redirect? Or can they see the
    actual page? Please help. ....
  4. Countdown Till Redirect
    (4)
    ok here is a question: how would i do something that says you will be redirected in 15 seconds and
    then changes the number till the redirection takes place. this is planned for a custom 404 error
    page. im not just asking for the countdown but also how to redirect at all. thankfull for any
    help /smile.gif' border='0' style='vertical-align:middle' alt='smile.gif' /> Lucas....
  5. Redirect Code Help
    (8)
    Can someone give me the code which redirects you automatically in the whole page instead of only in
    the frame? I'm using this code, but it just redirects inside a frame... CODE But now
    .tk has added a ad to the pages so I don't want to use it anymore, so I want that people
    entering the site is being redirected to the "real" domain name now.......

    1. Looking for url, redirection, javascript, html, redirect, scripts

Searching Video's for url, redirection, javascript, html, redirect, scripts
See Also,
advertisement


Url Redirection = Javascript+html - Redirect using scripts!

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com