spyke01 Posted September 20, 2006 Share Posted September 20, 2006 i have a div that i need to focus the page on so that the user can see their new comment flashing. I am using scriptaculous from script.aculo.usThe div:[CODE]<div id="11" class="comment" onload="setforcus(document.11); new Effect.Highlight(this); new Effect.Highlight(this);"> <a href="http://www.fasttracksites.com">paden</a><br /> <small>Posted on Sep 20, 2006</small><br /><br /> asdasd</div>[/CODE]heres the full page: [url=http://www.fasttracksites.com/demos/blog/index.php?p=viewentry&id=1]http://www.fasttracksites.com/demos/blog/index.php?p=viewentry&id=1[/url]the page just stays at the top, any ideas? Quote Link to comment Share on other sites More sharing options...
fenway Posted September 21, 2006 Share Posted September 21, 2006 What's setfocus()? Quote Link to comment Share on other sites More sharing options...
spyke01 Posted September 21, 2006 Author Share Posted September 21, 2006 from what i saw on google you can do setfocus(document.item) instead of document.item.focus() i tried both ways however to no avail Quote Link to comment Share on other sites More sharing options...
obsidian Posted September 21, 2006 Share Posted September 21, 2006 you're referring to document.l1, but it's your ID that is l1, and when you refer to your elements in javascript, it refers to the NAME. to focus on what you're after, you'll want to use this:[code]<body onload="document.getElementById('l1').focus()">[/code]also, a div doesn't have an onload trigger, only the document (body) has that. i'm not sure if the div can take a focus or not, but it's worth a try. Quote Link to comment Share on other sites More sharing options...
spyke01 Posted September 21, 2006 Author Share Posted September 21, 2006 if a div wont take a focus, how can i move down the page to a section without using an "a name" tag? Quote Link to comment Share on other sites More sharing options...
obsidian Posted September 21, 2006 Share Posted September 21, 2006 well, with the id already set, you can refer to a div the same way you would with an anchor tag. for instance, if your div has an id of "div03", you can drop down to it by hitting a link with the href of "#div03". so, you just need to reference the div id instead. here is a quick PHP script that will generate trash content that you can play with and see how they react:[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title><style type="text/css">body { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px;}div { border: 1px solid #9EB9CF; margin: 10px; padding: 10px;}</style></head><body><?php$links = array();for ($i = 0; $i < 20; $i++) { $links[] = sprintf("<a href=\"#div%02d\">$i</a>", $i);}echo implode(" | ", $links);for ($i = 0; $i < 20; $i++) { printf("<div id=\"div%02d\">\n", $i); echo "<h1>Div $i</h1>\n"; for ($j = 0; $j < 15; $j++) { echo ($j + 1) . "<br />\n"; } echo "</div>\n";}?></body></html>[/code] Quote Link to comment Share on other sites More sharing options...
fenway Posted September 21, 2006 Share Posted September 21, 2006 Almost everything can take focus, at least in IE, if it's visible. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.