Jump to content
xisto Community
David252a91

Body Onload Question

Recommended Posts

Welcome to Xisto.Have you tried something like:<body onload="window.location.href='yoursitehere.com should automatically redirect all your visitors once it reaches the body tag.

Share this post


Link to post
Share on other sites

<body onload="window.location.href='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


Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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



<body onload="window.location.href='yoursitehere.com';


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


Share this post


Link to post
Share on other sites

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

winndow.location.href='http://yoursitehere.com;;'>http://yoursitehere.com;;
at the begining of the page.

Also, you can achieve this same functionallity using a php header function like this:
<?phpHeader('Location: http://yoursitehere.com;
Best regards,

Share this post


Link to post
Share on other sites

@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/154/301-redirects-how-to-redirect-your-website/

:P

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.