Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

window.open Search using QUOTES ??

Status
Not open for further replies.
Here's a test harness which demonstrates the escape function for you:

Code:
<html>
<head>
	<script type="text/javascript">
	<!--
		function doSearch() {
			var searchURL = '[URL unfurl="true"]http://www.google';[/URL]
			searchURL += document.forms[0].whichGoogle.options[document.forms[0].whichGoogle.selectedIndex].value;
			searchURL += '/search?hl=en&ie=UTF-8&q=';
			searchURL += escape(document.forms[0].searchTerms.value);
			document.location = searchURL;
		}
	//-->
	</script>
</head>
<body>
	<form>
		Select which Google site to search:
		<select name="whichGoogle">
			<option value=".co.uk">google.co.uk</option>
			<option value=".com">google.com</option>
		</select><br />
		Enter your search query:
		<input type="text" size="50" name="searchTerms"><br />
		<input type="button" onclick="doSearch();" value="Search!">
	</form>
</body>
</html>

Hope this helps,
Dan
 
Thanks Dan!!!

How would this script look using the "escape" and "unescape" ???

Thanks again.
 

>> How would this script look using the "escape" and "unescape" ???

As it uses escape already, I'm not sure why you're asking the question. Unescape would not need to be used at all.

Dan
 
I think I made my last post at the same time as you did :)

Well,
I should have mentioned this is for a toolbar.

It adds a list to the registry and each url is listed and when you enter in the toolbar, your search term,
it replaces the %s with the search term.

I want to have this url


to look something like this

javascript:void(window.open("
so the toolbar opens a new window. The problem with that one is that it works but I cant use " " when needed.

This one below, adds quotes but they are permanent so It always searches with Quotes.

window.open("

Any ideas what will work?

Thanks for your help!!!!
 

I don't understand what/why you don't understand. My example clearly shows you how to do this using JavaScript.

If you want to do it using JavaScript, then the example should be fine for your needs. If you don't, and instead you want to do it in whatever language you're writing your toolbar in, then I suggest yuo seek help in a more appropriate forum.

Can you explain in more depth what is wrong with the example I gave, and why it doesn't suit your needs? What does the code not do that it should do?

Dan
 
First off... we're in a Javascript forum here. Are you certain that the root of this thread is really a javascript question?

It seems to me that you are mixing your explainations of what it is you want. On the one hand you ask how to put speech marks into a URL, then somehow it's merged into a "toolbar" (by the way... what is a toolbar - in context to this forum?), and finally you say that the solution is HTML and yet the solution doesn't use HTML.

You should be able to "pre-parse" the %s variable, replacing any speech marks with the appropriate escaped character using Javascript.

Maybe it would be easier to take 5 minutes and describe the code you are writing - and don't hold anything back! You know your code and the project you are working on -- we have no idea.

If you want a better answer than you have here (and Dan's solution is fine) then you will have to do a better job at defining your question. Saying that your solution doesn't use HTML is not helping.

Jeff
 
>> The example you gave is in html

The example I gave of the escape feature was in JavaScript. The test harness surrounding it was in HTML. Given that you posted in a JavaScript forum, asking questions about JavaScript methods, I assumed that you'd want the main bulk of the code in JavaScript - which it was.

I still don't understand why you cannot take the code I gave and modify it for your purposes... Nor do I (fully) understand what you want to do that you cannot do using the methods I've described. However, here's what I'm guessing you want to see (although I still cannot be sure, because I'm just not getting a good solid explanation from you):

Code:
javascript:void(window.open('[URL unfurl="true"]http://www.google.com/search?hl=en&ie=UTF-8&q='[/URL] + escape(searchQuery)));

Where "searchQuery" is your string (whether containing quotes or not).

Dan
 
Dan,
Yes that is how I needed to see it. Sorry my explenation was not good. Im new to this.
Anyways the code you posted last did not do anything at all.
Did it work for you?
I do appreciate your help.
Thanks
 

I didn't test it - as I said, I was giving you what I thought you wanted to see, as you didn't seem to get my previous post which had worked for me.

Does the code error for you? How about you post the code that you have, and for us to try and debug it, rather than me posting working code that you are unable to do anything with?

Dan


 
BabyJeffy said:
If you want a better answer than you have here (and Dan's solution is fine) then you will have to do a better job at defining your question.

I guess you missed that suggestion of mine.

Jeff
 
These two here work with double quotes but not single quotes
so a search for "O Riely" would work but a search for O'Riely would fail

javascript:void(window.open('javascript:void(window.open("
These two work with single Quotes but not double, so O'Riely works but not "O Riely"

javascript:void(window.open("javascript:void(window.open("

This works kinda...
javascript:window.open("
except '\%s'\ will always leave the ' on the right of the search term e.g. a search for ORiely always shows as ORiely'

Either way, none of them will let a search for "O'Riley"

I hope this made some sence, and was helpful
 
You asked the error.. It just says done, no window opens or anything.
 
Now you've added another layer to the problem - single quotes are not something you've mentioned before in any of your posts. Talk about ever-changing specs!

I'm guessing by the one line of JS code that you're giving us (without any other code around it - which isn't too helpful) that you want to run this when an HREF is clicked.

So... here's my earlier code modified to run from an HREF, that will work with no quotes, single quotes, or double quotes. I've even tested it with single AND double quotes, and it works 100% of the time.

If this doesn't work for you, or if my above assumption about the HREF is wrong, then I'm sorry - but I wont be able to help you any further, unless you think through and explain your problem in a better manner, and provide more than just the same line of code (i.e. give us some context here!).

Code:
<html>
<head></head>
<body>
	<form>
		<input type="text" name="searchQuery">
		<br />
		Click <a href="javascript:void(window.open('[URL unfurl="true"]http://www.google.co.uk/search?hl=en&ie=UTF-8&q='[/URL] + escape(document.forms[0].searchQuery.value)));">here</a> to search Google.co.uk with your search query
	</form>
</body>
</html>

Hope this helps,
Dan
 
its not an href link.

It is a link in the registry that will launch when clicking GO on the toolbar.

The links all look something like this.

javascript:void(window.open("
So If it works 100% then can you make that code sorounded by html that you posted, look like this link?

Then it will work perfect. Thanks again man.


Heres a sample of the registry....

REGEDIT4

[HKEY_CURRENT_USER\Software\VPop\Acid_Bar\Options]
"ShowButtonText"=dword:00000001
"ShowHighlightButton"=dword:00000001
"ShowWordSearchButtons"=dword:00000001
"CurrentVersion"=dword:00000001
"MenuOrder"="1|2|3"
"CurrentEngine"="2"

"EngineName1"="WEB: alltheweb"
"EngineURL1"="javascript:void(window.open(""EngineName2"="WEB: teoma"
"EngineURL2"="javascript:void(window.open(""EngineName3"="WEB: yahoo"
"EngineURL3"="javascript:void(window.open("
 

You need to escape the string before storing it in the registry. I suggest you read up on whatever language your writing this toolbar in, and then seek help in the most appropriate forum.

One piece of advice - tell them in the first post what you want, instead of drawing it out over many posts, and only really saying what you want 8 posts down the line.

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top