Solved

multisite search script not working.....urgent

Posted on 2006-11-08
11
198 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
Comment Utility
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
Comment Utility
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
Comment Utility
<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
 

Author Comment

by:arasuworld
Comment Utility
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
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
no. perhaps a script in the page of wiki.
0
 

Author Comment

by:arasuworld
Comment Utility
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
Comment Utility
I will have a look...

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

Expert Comment

by:Michel Plungjan
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

743 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now