It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

Body onLoad Click link

Body onLoad Click link

Postby azylka on Thu Dec 24, 2009 4:16 am

Hi guys. I have a quick question. What's the code for having a link with the id "autoid" clicked when the body of my html code loads?

Thanks,
Alex
azylka
 
Posts: 2
Joined: Thu Dec 24, 2009 4:14 am

Re: Body onLoad Click link

Postby dflynn on Tue Dec 29, 2009 2:13 pm

You want to click a link automatically when the page loads? Like a page redirect??

You don't need Javascript for a redirect.This will do the job for you:

<met a HTTP-EQUIV="REFRESH" content="0; url=http://www.yourdomain.com/index.html">
User avatar
dflynn
500+ Club
 
Posts: 860
Joined: Wed Oct 03, 2007 9:06 pm
Location: Guelph, Canada

Re: Body onLoad Click link

Postby rangana on Wed Dec 30, 2009 10:20 pm

Hi Alex,

Good day!

Code: Select all
<script type="text/javascript">
// start JSON   
var ray = {
   autoLoad: function (obj) {
      var els = document.getElementsByTagName('*'); // Get all elements in DOM
      for (var i = 0 ; i < els.length ; i++) {
         if (els[i].id.toLowerCase() == obj.id)
            location.href = els[i].href;
      }
   }
}

window.addEventListener?window.addEventListener('load',function () {
   ray.autoLoad({id:'autoid'});
},false):window.attachEvent('onload',function() {
   ray.autoLoad({id:'autoid'});
}); // IE : FF
</script>


Hope that helps.
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 5:14 am
Location: Cebu City Philippines


Who is online

Users browsing this forum: No registered users and 6 guests