Solved

multisite search script not working.....urgent

Posted on 2006-11-08
11
201 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

803 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