Solved

multisite search script not working.....urgent

Posted on 2006-11-08
11
202 Views
Last Modified: 2010-04-06
this is multisitesearch script that i have. and i've added some extra iframes into it. the iframe that i added are appering in the webpage but when doing a search only the first two iframes are refreshing and giving me the search that i wanted.the other two iframes are not refreshing and giving any result. what is wrong here?

<head>
<script type="text/javascript">
function handlelink(obj, frameid){
var search, url, addon="";
search=document.forms.form1.In1.value.split(" ");
for (i=0; i<search.length-1; i++) addon=addon+search[i]+"+"
addon=addon+search[search.length-1]
url=obj.href+addon;
document.getElementById(frameid).src=url;
//window.frames[frame_].src=url;
return false;
}

</script>
</head>
<body onload='document.forms.form1.In1.focus()'>
<li><a id=link1 class="current" href="http://www.google.com/search?q=" onClick="return handlelink(this,'cwindow1')">Google</a></li>
<li><a id=link2 href="http://search.yahoo.com/search?p=" onClick="return handlelink(this,'cwindow2')">Yahoo</a></li>
<li><a id=link3 href="http://www.google.com/search?q=" onClick="return handlelink(this,'cwindow3')">Google</a></li>
<li><a id=link4 href="http://search.yahoo.com/search?p=" onClick="return handlelink(this,'cwindow4')">Yahoo</a></li>
<form name=form1 onsubmit="handlelink(document.getElementById('link1'),'cwindow1'); return handlelink(document.getElementById('link2'),'cwindow2')">
Search query: <input name=In1 value="apples oranges">
<input type=submit name="Search" >
</form>
<iframe name="cwindow1" id="cwindow1" style="border:2px solid black" width=279 height=419 src="http://www.google.com/search"></iframe>
<iframe name="cwindow2" id="cwindow2" style="border:2px solid black" width=279 height=419 src="http://search.yahoo.com/"></iframe>
<iframe name="cwindow3" id="cwindow3" style="border:2px solid black" width=279 height=419 src="http://search.yahoo.com/"></iframe>
<iframe name="cwindow4" id="cwindow4" style="border:2px solid black" width=279 height=419 src="http://search.yahoo.com/"></iframe>




0
Comment
Question by:arasuworld
  • 5
  • 3
  • 3
11 Comments
 
LVL 2

Expert Comment

by:bowen18
ID: 17901258
Looks like you didn't add the other two frames on the submit:

<form name=form1 onsubmit="handlelink(document.getElementById('link1'),'cwindow1'); return handlelink(document.getElementById('link2'),'cwindow2')">

Plus you have unneeded ) after the two link names.  The following should work:

<form name=form1 onsubmit="handlelink(document.getElementById('link1','cwindow1'); return handlelink(document.getElementById('link2','cwindow2'); return handlelink(document.getElementById('link3','cwindow3'); return handlelink(document.getElementById('link4','cwindow4')">
0
 
LVL 2

Expert Comment

by:bowen18
ID: 17901327
I apologize, my previous post is incorrect.

This should be the correct line:

<form name=form1 onsubmit="handlelink(document.getElementById('link1'),'cwindow1'); handlelink(document.getElementById('link2'),'cwindow2'); handlelink(document.getElementById('link3'),'cwindow3'); return handlelink(document.getElementById('link4'),'cwindow4')">
0
 
LVL 75

Assisted Solution

by:Michel Plungjan
Michel Plungjan earned 500 total points
ID: 17905212
<head>
<script type="text/javascript">
function handlelink(obj, frameid){
  var search, url, addon="";
  search=document.forms.form1.In1.value.replace(' ','+')
  url=obj.href+search;
  document.getElementById(frameid).src=url;
  return false; // disallow the href
}

function handleLinks() {
  for (var i=1;i<=4;i++) handlelink(document.getElementById('link'+i),'cwindow'+i);
  return false;
}
</script>
</head>
<body onload='document.forms.form1.In1.focus()'>
<li><a id=link1 target="cwindow1" class="current" href="http://www.google.com/search?q=" onClick="return handlelink(this,this.target)">Google</a></li>
<li><a id=link2 target="cwindow2" href="http://search.yahoo.com/search?p=" onClick="return handlelink(this,this.target)">Yahoo</a></li>
<li><a id=link3 target="cwindow3" href="http://www.google.com/search?q=" onClick="return handlelink(this,this.target)">Google</a></li>
<li><a id=link4 target="cwindow4" href="http://search.yahoo.com/search?p=" onClick="return handlelink(this,this.target)">Yahoo</a></li>

<form name=form1
onsubmit="return handleLinks(this)">Search query: <input name=In1 value="apples oranges">
<input type=submit name="Search" >
</form>
<iframe name="cwindow1" id="cwindow1" style="border:2px solid black" width=279 height=419 src="http://www.google.com/search"></iframe>
<iframe name="cwindow2" id="cwindow2" style="border:2px solid black" width=279 height=419 src="http://search.yahoo.com/"></iframe>
<iframe name="cwindow3" id="cwindow3" style="border:2px solid black" width=279 height=419 src="http://search.yahoo.com/"></iframe>
<iframe name="cwindow4" id="cwindow4" style="border:2px solid black" width=279 height=419 src="http://search.yahoo.com/"></iframe>
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:arasuworld
ID: 17907830
i had the first script working on 2 iframes. but when i try to add 3rd and 4th the iframe, its appearing in webpage but no search result. the script that bowen18 and mplugjan gave works on the 3rd and 4th iframe. so when i try to add 5th and 6th iframe in mplugjan's script the same problem appears. the 5th and 6th iframe appearing but not responding to query. so if i want 5th iframe or 6th iframe (or any number of iframes) where should add or modify the script?
0
 
LVL 2

Expert Comment

by:bowen18
ID: 17907868
If you want to add a 5th, 6th, 7th, etc., you would simply need to change number 4 in mplungjan's script on this line:

for (var i=1;i<=4;i++) handlelink(document.getElementById('link'+i),'cwindow'+i);

To:

for (var i=1;i<=5;i++) handlelink(document.getElementById('link'+i),'cwindow'+i);
or
for (var i=1;i<=6;i++) handlelink(document.getElementById('link'+i),'cwindow'+i);
or
for (var i=1;i<=7;i++) handlelink(document.getElementById('link'+i),'cwindow'+i);

It just depends on how many searches you want to add.
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
ID: 17910168
change

function handleLinks() {
  for (var i=1;i<=4;i++) handlelink(document.getElementById('link'+i),'cwindow'+i);
  return false;
}
to

function handleLinks() {
  var iFrames = document.getElementsByTagName("iframe")
  for (var i=1;i<=iFrames.length;i++) handlelink(document.getElementById('link'+i),'cwindow'+i);
  return false;
}
assuming you only use the iframes for the links
0
 

Author Comment

by:arasuworld
ID: 17922355
function handleLinks() {
  var iFrames = document.getElementsByTagName("iframe")
  for (var i=1;i<=iFrames.length;i++) handlelink(document.getElementById('link'+i),'cwindow'+i);
  return false;
}


the given script "faulty". after i add one more iframe  (and change href to http://en.wikipedia.org/wiki/Special:Search?search=) and begin searching,  the result appering in iframe but redirected to wikipedia page after 4 seconds. is it becouse of the the script line  (var i=1;i<=iFrames.length;i++) ?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 17922996
no. perhaps a script in the page of wiki.
0
 

Author Comment

by:arasuworld
ID: 17924216
follow up question.so how do i make a wikipedia search in a iframe without the site redirecting?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 17924659
I will have a look...

BTW you split points between me and me :)
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 17924693
Here - no way to load wikipedia's homepage without hitting this framebuster:

view-source:http://en.wikipedia.org//skins-1.5/common/wikibits.js?24

// Un-trap us from framesets
if (window.top != window)
      window.top.location = window.location;

Here is a solution


<head>
<script type="text/javascript">
function handlelink(obj, target){
  var search, url;
  search=document.forms[0].In1.value.replace(' ','+')
  url=obj.href+search;
  alert(url+':'+target)
  window.open(url,target);
  return false; // disallow the href
}


function handleLinks() {
  var iFrames = document.getElementsByTagName("iframe")
  for (var i=1;i<=iFrames.length;i++) {
    var link = document.getElementById('link'+i)
    var target=document.getElementById('link'+i).target;
    handlelink(link,target);
  }    
  return false;
}
</script>
</head>
<body onload='document.forms.form1.In1.focus()'>
<li><a id=link1 target="cwindow1" class="current" href="http://www.google.com/search?q=" onClick="return handlelink(this,this.target)">Google</a></li>
<li><a id=link2 target="cwindow2" href="http://search.yahoo.com/search?p=" onClick="return handlelink(this,this.target)">Yahoo</a></li>
<li><a id=link3 target="cwindow3" href="http://www.google.com/search?q=" onClick="return handlelink(this,this.target)">Google</a></li>
<li><a id=link4 target="cwindow4" href="http://search.yahoo.com/search?p=" onClick="return handlelink(this,this.target)">Yahoo</a></li>
<li><a id=link5 target="WIKI" href="http://en.wikipedia.org/wiki/Special:Search?search=" onClick="return handlelink(this,this.target)">Wikipedia</a></li>
 

<form name=form1
onsubmit="return handleLinks(this)">Search query: <input name=In1 value="apples oranges">
<input type=submit name="Search" >
</form>
<iframe name="cwindow1" id="cwindow1" style="border:2px solid black" width=279 height=419 src="http://www.google.com/search"></iframe>
<iframe name="cwindow2" id="cwindow2" style="border:2px solid black" width=279 height=419 src="http://search.yahoo.com/"></iframe>
<iframe name="cwindow3" id="cwindow3" style="border:2px solid black" width=279 height=419 src="http://search.yahoo.com/"></iframe>
<iframe name="cwindow4" id="cwindow4" style="border:2px solid black" width=279 height=419 src="http://search.yahoo.com/"></iframe>
<iframe name="cwindow5" id="cwindow4" style="border:2px solid black" width=279 height=419 src="javascript:'Wikipedia breaks my frames'"></iframe>
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question