Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Yahoo & Altavista

Quote Reply
Yahoo & Altavista
Just wondering, when you go to yahoo or altavista or most major search engines, the cursor pops up in the search box automatically, how would you make it do that for LinksSQL???
Thanks

</not a clue>
Quote Reply
Re: [Dinky] Yahoo & Altavista In reply to
A bit of javascript does it. Insert

Code:


<body onLoad="document.forms.searchform.query.focus()">


and then give your form the name searchform.

That should do it.
Quote Reply
Re: [gotze] Yahoo & Altavista In reply to
That's a really neat idea :)

for those wondering, you can add this accross the site with a few changes to the default template set.

In your admin->build->template globals area add a new global:

body_tags

that has the information from body_tag _except_ the opening <body and closing >, ie _just_:

bgcolor="white" leftmargin="0" topmargin="10" marginheight="10" marginwidth="0" rightmargin="0"><basefont face="Arial" color="black" size="2"

(0r whatever you have changed that to).

Now, at the top of all your templates, you can change the <%body_tag%> to:

<body <%body_tags%> >

And you can now add items to the <body> tag without having to re-edit page after page. Just make changes to _both_ the body_tag and body_tags globals, and they should be next to each other in globals.txt so it's easy to remember to do. :)

(It's probably better to do it this way, so you can specifically decide what pages you want the javascript (or any other page-specific tag) on, and keep "default" and basic tags in the <%body_tags%> and <%body_tag%> globals. You could also make a <%body_tag_search_java%> global, and use that... but I like the idea of being able to edit/change the HTML <body ....> tag in a document, while keeping the the default <%body_tags%> )

Now to add the search box focus ability,

Change search.html to have:

<body onLoad="document.forms.searchform.query.focus()" <%body_tags%> >

and the

<form action="<%db_cgi_url%>/search.cgi" method="GET">
to
<form name="searchform" action="<%db_cgi_url%>/search.cgi" method="GET">


If you do the same thing to include_search_bar.html (name the form "searchform"), and make the change to the top of the files you include it on (the expanded <body onload.... <%body_tags%> >), when the page loads, the cursor will be on that form.

Going back to the above, if you keep the javascript code in the actual <body ... > tag, then if you have 2 or 3 forms on a page, like on home.html, you can pick which form you want highlighted or selected on a page by page basis. You can use searchform as your default, unless you pick soemthing else (I didn't want to use 'default', since it's not automatic, you have to edit each page, but you only need to do that once.).


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Yahoo & Altavista In reply to
Quote:
That's a really neat idea :)

You didn't know that could be done? Smile

To save having to add a name to all your forms it would be best to tweak that javascript to:

document.forms[0].query.focus();

....of course it assumes the search box is the first form on the page.

That's just an optional extra anyway.

Btw, the javascript can be written as..

document.form_name.query.focus();

...the "forms." part can be left out.

Last edited by:

Paul: May 1, 2003, 5:39 AM
Quote Reply
Re: [Paul] Yahoo & Altavista In reply to
Google uses a new script (I ripped the abopve method from them a while ago ..):

Code:
<script>
<!--
function sf(){document.f.q.focus();}
function c(p,l,e){var f=document.f;if (f.action && document.getElementById) {var hf=document.getElementById("hf");if (hf) {var t = "<input type=hidden name=tab value="+l+">";hf.innerHTML=t;}f.action = 'http://'+p;e.cancelBubble=true;f.submit();return false;}return true;}
// -->
</script>


I'm not sure what it does Blush

John
Quote Reply
Re: [gotze] Yahoo & Altavista In reply to
The first function is focusing the search field, the second is adding a hidden element to the form when the function is run and then it submits the form.
Quote Reply
Re: [gotze] Yahoo & Altavista In reply to
<G>

Actually, what was the most _neat_ about it, was that it suddenly dawned on me to use:

<body <%body_tags%>> to allow default tags, but extra formatting :)

The javascript was just a cool excuse for coming up with it ;) <G>


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Yahoo & Altavista In reply to
Sly Thanks guys, that worked like a charm!!!

</not a clue>