Nov 8, 2009

Body Onload Question

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Programming > Scripting > JavaScript

Body Onload Question

David252a91
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?

Comment/Reply (w/o sign-up)

toby
Why not Meta tags?

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

Comment/Reply (w/o sign-up)

WeaponX
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.

Comment/Reply (w/o sign-up)

faulty.lee
QUOTE(WeaponX @ Nov 27 2006, 06:34 AM) *

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


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

Comment/Reply (w/o sign-up)

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.

Comment/Reply (w/o sign-up)

borlafu
QUOTE(CaptainRon @ Nov 27 2006, 06:27 AM) *

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.


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.

 

 

 


Comment/Reply (w/o sign-up)

TavoxPeru
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,

Comment/Reply (w/o sign-up)

FirefoxRocks
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?

Comment/Reply (w/o sign-up)

borlafu
@FirefoxRocks:

TavoxPeru has just written an example tongue.gif

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

wink.gif

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 : Onload


    Looking for body, onload, question

See Also,

*SIMILAR VIDEOS*
Searching Video's for body, onload, question
advertisement



Body Onload Question

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