bookmark - Body Onload Question

Body Onload Question

 
 Discussion by David252a91 with 8 Replies.
 Last Update: November 29, 2006, 7:01 pm
 
bookmark - Body Onload Question  
    
free web hosting
 
Hi, I was sondering something. Is it possible to do a onLoad property in a body tag that automaticly redirects you to another page? Or onLoad to a function that redirects you to another page?

Sun Nov 26, 2006    Reply    New Discussion   


Why not Meta tags?

You could write a function that changes the current window, and stick that in <body onLoad(here)>

Sun Nov 26, 2006    Reply    New Discussion   

Welcome to Astahost.

Have you tried something like:

<body onload="window.location.href='http://www.yoursitehere.com'">

That should automatically redirect all your visitors once it reaches the body tag.

Sun Nov 26, 2006    Reply    New Discussion   

QUOTE (WeaponX)


<body onload="window.location.href='http://www.yoursitehere.com'">

Link: view Post: 92700


Nothing simpler than that already.

By the way, why do you want to do the redirection in the onLoad? If you have nothing you want to show on that page, and want to redirect immediately, put that code in the javascript section at the beginning of the page, that way it doesn't have to wait until the page finished loading. The browser will redirect as soon as it see that code.

Good Luck

Mon Nov 27, 2006    Reply    New Discussion   


In case you want to make sure that every thing in the current page is visible to the user, then in the head section, write a JS to set the window.onload=toSomeFunction; and declare that function with the redirection code. eg.
function toSomeFunction()
{
window.location.href="http://somesite.com";
}

This is what is done at download sites which make u wait for the contents of the window to load first and then start the download.

Mon Nov 27, 2006    Reply    New Discussion   

QUOTE (CaptainRon)


In case you want to make sure that every thing in the current page is visible to the user, then in the head section, write a JS to set the window.onload=toSomeFunction; and declare that function with the redirection code. eg.
function toSomeFunction()
{
window.location.href="http://somesite.com";
}

This is what is done at download sites which make u wait for the contents of the window to load first and then start the download.

Link: view Post: 92720


It's not neccesary to declare a new function for doing such a simple operation, the code mentioned before has the same use:

QUOTE

<body onload="window.location.href='http://www.yoursitehere.com'">


And it's sorter, so you will use less bandwidth.

Mon Nov 27, 2006    Reply    New Discussion   

As you can see, there are a lot of ways to achieve the same result, i prefer to use

CODE

winndow.location.href='http://www.yoursitehere.com';

at the begining of the page.

Also, you can achieve this same functionallity using a php header function like this:

CODE

<?php
Header('Location: http://www.yoursitehere.com');
?>

Best regards,

Mon Nov 27, 2006    Reply    New Discussion   

I've also heard of HTTP redirects which the W3C recommends. It doesn't use META tags and JavaScript. How does that work? Can someone show me an example?

Wed Nov 29, 2006    Reply    New Discussion   

@FirefoxRocks:

TavoxPeru has just written an example :P

HTTP redirects consists on sending (from the server) a HEADER to the client telling him that the page has changed it's location permanently or just temporaly and the URL to lacate it now.

You can see some examples of how to redirect a webpage here:

http://www.webconfs.com/how-to-redirect-a-webpage.php

:P

Wed Nov 29, 2006    Reply    New Discussion   

Quickly Post to Body Onload Question  w/o signup Share Info about Body Onload Question  using Facebook, Twitter etc. email your friend about Body Onload Question Print
Reply / Comment Ask a Question? Share / Bookmark E-Mail a Friend Print

Google Map Like Pins On Image Please helpe me regarding this.  Google Map Like Pins On Image Please helpe me regarding this. (4) (5) How To Trap The URL To Which A User Is Navigating To?   How To Trap The URL To Which A User Is Navigating To?