Taking over page

2 views
Skip to first unread message

xfire.o...@gmail.com

unread,
Sep 17, 2006, 7:46:14 PM9/17/06
to Google AJAX Search API
Hi, I am trying to get this on my page without it totally taking over
my page. http://jdprofessionaltraining.com/fixin_search.htm I have
tried moving things around but it either takes it completely over or
screws up the template.

mhl

unread,
Sep 17, 2006, 8:03:14 PM9/17/06
to Google AJAX Search API
I am not sure what you mean by it "taking over". When I view the page,
the ajax search control is sitting within the div id=searchcontrol. I
do notice that your page has two <body> elements. You should fix that
for sure. In our samples, we typically have <body
onload="OnLoad()"><div id="searchcontrol"></div></body>. You don't have
to copy this code and cut/paste it onto your page. What you have to do
is simply tell the search control where you want it to draw. This can
be anywhere on your page, in any div, in a table, in the sidebar, etc.

jon heckman

unread,
Sep 17, 2006, 8:07:32 PM9/17/06
to Google-AJAX...@googlegroups.com
If you look at the code or watch the loading it will show you what is supposed to be there below the api. Or you could look at jdprofessionaltraining.com . Also since in <body
onload="OnLoad()"><div id="searchcontrol"></div></body> the highlighted part is <body> what do I change it to so I dont have 2 body elements because I tried deleting that from it and the api didnt even show at all.

mhl

unread,
Sep 18, 2006, 11:23:18 AM9/18/06
to Google AJAX Search API
just delete the <body> element and its closing </body> tag. Keep the
<div id="searchcontrol"></div> and place this construct wherever you
want the search control to appear. Then find the existing <body>
element and change it to call your onload handler and you should be all
set. For instance, right now, you have:
<body>
<!-- Begin Masthead -->
...
<div id="content">
<!-- SiteSearch Google -->
<form method="get" action="http://www.google.com/custom" target="_top">
...
</form>

Change this to:

<body onload="OnLoad()">
<!-- Begin Masthead -->
...
<div id="content">
<!-- google ajax search api -->
<div id="searchcontrol">Loading...</div>
</div>

jon heckman

unread,
Sep 18, 2006, 4:25:51 PM9/18/06
to Google-AJAX...@googlegroups.com
So if I understand correctly all I need to change is the body tag and move onload="OnLoad()" to the top <body> I did that but it still doesn't work http://www.jdprofessionaltraining.com/fixin_search.htm
--
check out my site at http://jonsupersite.com , has videos, games, and more.

mhl

unread,
Sep 18, 2006, 4:45:57 PM9/18/06
to Google AJAX Search API
Looks like you are using dojo?

http://www.dev411.com/blog/2006/07/13/dojo-dojo-addonload-vs-body-onload-and-window-onload

Dojo calls window.onload itself, SO your body.onload is conflicting
with dojo. Sorry that I didn't focus on your dojo issues before...

When using dojo, you can not use <body onload=""/> or window.onload.
Dojo provides a utility function for you to use instead.

In you script, do something like:
<script type="text/javascript">
//<![CDATA[

dojo.addOnLoad( function OnLoad() {
// Create a search control
var searchControl = new GSearchControl();
...
});
...
</script>

jon heckman

unread,
Sep 18, 2006, 5:12:19 PM9/18/06
to Google-AJAX...@googlegroups.com
So I should replace
    function OnLoad() {
      // Create a search control
      var searchControl = new GSearchControl();

with

   dojo.addOnLoad( function OnLoad() {
     // Create a search control
     var searchControl = new GSearchControl();

In the api code and get rid of the body elemets in

<body onload="OnLoad()">
    <div id="searchcontrol"/>
  </body>

And Should I still put onload="OnLoad()" in the top body, because without onload="OnLoad()" added to body it it doesnt show up at all and with it in body it still does the same thing.I just uploaded it without the body change


On 9/18/06, mhl <mhl...@gmail.com> wrote:

mhl

unread,
Sep 22, 2006, 6:41:48 PM9/22/06
to Google AJAX Search API
Sorry for the delay. Some of the typepad guys were having a similar
problem with conflicting loads. One very easy way to deal with this
when you are in an environment where some runtimes are glomming
directly onto window.onload is to use addEventListner/attachEvent. This
is a safe way to ensure your code gets called no matter what else is
happening in the page.

To use this technique remove your onload= attribute in the body tag.

Then in the script block that contains your onload handler, the one
that activates your search control, do something like this:
<script type="text/javascript">
function myOnLoad() {
var sc = new GSearchControl();
sc.addSearcher(new GwebSearch());
sc.draw(document.getElementById("searchControl"));
}

// arrange for myOnLoad to get called
registerLoadHandler(myOnLoad);

function registerLoadHandler(handler) {
var node = window;
if (node.addEventListener) {
node.addEventListener("load", handler, false);
} else if (node.attachEvent) {
node.attachEvent("onload", handler);
} else {
node['onload'] = handler;
}
}
</script>

<body>
<div id="searchControl">Loading...</div>
</body>

Take a look at these blog based samples which both use this trick

http://ajaxsearch.typepad.com
http://ajaxsearch.blogspot.com

jon heckman

unread,
Sep 22, 2006, 8:14:34 PM9/22/06
to Google-AJAX...@googlegroups.com
Hi, thanks that fixed the problem with the page not loading but for some reason now it only searches the web and not what I told it to search


On 9/22/06, mhl <mhl...@gmail.com> wrote:

Sorry for the delay. Some of the typepad guys were having a similar
problem with conflicting loads. One very easy way to deal with this
when you are in an environment where some runtimes are glomming
directly onto window.onload is to use addEventListner/attachEvent. This
is a safe way to ensure your code gets called no matter what else is
happening in the page.

To use this technique remove your onload= attribute in the body tag.

Then in the script block that contains your onload handler, the one
that activates your search control, do something like this:
<script type="text/javascript">
  function myOnLoad() {
    var sc = new GSearchControl();
    sc.addSearcher(new GwebSearch());
    sc.draw(document.getElementById("searchControl"));
  }

  // arrange for myOnLoad to get called
  registerLoadHandler(myOnLoad);

  function registerLoadHandler(handler) {
    var node = window;
    if (node.addEventListener) {
      node.addEventListener ("load", handler, false);

mhl

unread,
Sep 23, 2006, 12:40:50 AM9/23/06
to Google AJAX Search API
can you post the url of the page that isnt working?

jon heckman

unread,
Sep 23, 2006, 12:06:27 PM9/23/06
to Google-AJAX...@googlegroups.com
Hi, here is the page http://jdprofessionaltraining.com/fixin_search.htm


On 9/23/06, mhl <mhl...@gmail.com> wrote:

can you post the url of the page that isnt working?







mhl

unread,
Sep 23, 2006, 12:33:25 PM9/23/06
to Google AJAX Search API
Did you look closely at your code?

#1 - you re-introduced a second body tag. Get rid of it. Your page
already has a body element, you dont need/hand another.

#2 - the function myOnLoad is being executed. Look at what it does...
It creates a search control populated with a single GwebSearch().

#3 - my guess is that your complaint is that a function called
OnLoad(), which sets up some site restricted searchers, etc. is not
getting called? If that is your complaint, then based on the code you
put on that page, thats the expected behavior since you never called
OnLoad().

Here is how you fix this.

#1 remove the secondary <body> element
#2 decide where on your page you want the search control and wherever
you want it to appear put <div id="searchcontrol:>Loading...</div>
#3 Change this script block from:


<script type="text/javascript">
function myOnLoad() {
var sc = new GSearchControl();
sc.addSearcher(new GwebSearch());
sc.draw(document.getElementById("searchControl"));
}

// arrange for myOnLoad to get called
registerLoadHandler(myOnLoad);

function registerLoadHandler(handler) {
var node = window;
if (node.addEventListener) {

node.addEventListener("load", handler, false);


} else if (node.attachEvent) {
node.attachEvent("onload", handler);
} else {
node['onload'] = handler;
}
}
</script>

TO:
<script type="text/javascript">
// arrange for OnLoad to get called
registerLoadHandler(OnLoad);

function registerLoadHandler(handler) {
var node = window;
if (node.addEventListener) {

node.addEventListener("load", handler, false);


} else if (node.attachEvent) {
node.attachEvent("onload", handler);
} else {
node['onload'] = handler;
}
}
</script>

#4 Study my suggested change and make sure what I am asking you to do
makes sense and that you understand the change. If you don't understand
something, ask a question on the part you don't understand.

#5 Keep in mind that there is nothing special about the function named
myOnLoad() or OnLoad(). They are just function names and if you want
them to get executed, something needs to call them. The function that I
wrote for you called registerLoadHandler will arrange for a function of
your choice to be called when the page loads. In the code that you sent
this morning, you chose to have myOnLoad get called even though all of
the code in your app is in a function called OnLoad

Hope this is helpful. Good luck and keep in touch.

mhl

unread,
Sep 23, 2006, 12:45:22 PM9/23/06
to Google AJAX Search API
Did you look closely at your code?

#1 - you re-introduced a second body tag. Get rid of it. Your page
already has a body element, you dont need/hand another.

#2 - the function myOnLoad is being executed. Look at what it does...
It creates a search control populated with a single GwebSearch().

#3 - my guess is that your complaint is that a function called
OnLoad(), which sets up some site restricted searchers, etc. is not
getting called? If that is your complaint, then based on the code you
put on that page, thats the expected behavior since you never called
OnLoad().

Here is how you fix this.

#1 remove the secondary <body> element
#2 decide where on your page you want the search control and wherever
you want it to appear put <div id="searchcontrol:>Loading...</div>
#3 Change this script block from:

<script type="text/javascript">
function myOnLoad() {
var sc = new GSearchControl();
sc.addSearcher(new GwebSearch());
sc.draw(document.getElementById("searchControl"));
}

// arrange for myOnLoad to get called
registerLoadHandler(myOnLoad);

function registerLoadHandler(handler) {
var node = window;
if (node.addEventListener) {

node.addEventListener("load", handler, false);


} else if (node.attachEvent) {
node.attachEvent("onload", handler);
} else {
node['onload'] = handler;
}
}
</script>

TO:


<script type="text/javascript">
// arrange for OnLoad to get called
registerLoadHandler(OnLoad);

function registerLoadHandler(handler) {


var node = window;
if (node.addEventListener) {

node.addEventListener("load", handler, false);


} else if (node.attachEvent) {
node.attachEvent("onload", handler);
} else {
node['onload'] = handler;
}
}
</script>

#4 Study my suggested change and make sure what I am asking you to do

jon heckman

unread,
Sep 23, 2006, 12:53:10 PM9/23/06
to Google-AJAX...@googlegroups.com
If I understand you correctly then I have to edit that code and tell it which search to do or just leave it as is bcs as is the Loading... just stays there. And if I have to edit the code then how do I do that

On 9/23/06, mhl <mhl...@gmail.com> wrote:

mhl

unread,
Sep 23, 2006, 1:37:49 PM9/23/06
to Google AJAX Search API
when you call searchControl.draw() you are pointing the draw method at
the div containing the Loading... string. The .draw() method will
overwrite Loading. Send me the url to your page that doesn't work. Did
you write this page on your own? Or did you get help from someone local
to you?

jon heckman

unread,
Sep 23, 2006, 2:08:54 PM9/23/06
to Google-AJAX...@googlegroups.com
Here is the page http://jdprofessionaltraining.com/fixin_search.htm and I have created the site (except content) myself

On 9/23/06, mhl <mhl...@gmail.com> wrote:

mhl

unread,
Sep 23, 2006, 3:01:38 PM9/23/06
to Google AJAX Search API
In OnLoad(), you have the following:

// tell the searcher to draw itself and tell it where to attach
searchControl.draw(document.getElementById("searchcontrol"));

In your HTML you have the following:


<div id="searchControl">Loading...</div>

Note that in your OnLoad function, you are telling the system to draw
on top of an element called "searchcontrol", but in your HTML, it is
spelled "searchControl".

These languages are case sensative, so get these two places aligned and
things should work.

jon heckman

unread,
Sep 23, 2006, 3:33:16 PM9/23/06
to Google-AJAX...@googlegroups.com
Hey thanks for helping, that fixed that but I have one other question, How do I tell it the target when clicking on a link.

On 9/23/06, mhl < mhl...@gmail.com> wrote:

mhl

unread,
Sep 23, 2006, 3:51:14 PM9/23/06
to Google AJAX Search API
right after creating your search control, call .setLinkTarget()

Something like this. NOTE: substitute the name of your search control
fore coreSearch.

// create the search control
coreSearch = new GSearchControl();
coreSearch.setLinkTarget(GSearch.LINK_TARGET_SELF);

Reply all
Reply to author
Forward
0 new messages