Solved

multisite search script not working.....urgent

Posted on 2006-11-08
11
205 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

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

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

623 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