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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Probably simple but... How to Void a Prompt if text is selected?

Status
Not open for further replies.

humanfly199

Technical User
Jan 14, 2007
1
US
Hi, will someone please help with this.

The code prompts a pop up search box and if text is selected on a page it will be in the box automatically. (It's for a firefox extension)

I want to avoid the prompt if text is selected, so it will only prompt if nothing is selected. I think that I need to use "if & void" but I dont understand how to put it in there. The bookmarklet below does this perfectly. Will someone please help?


The Code..

Code:
function srch() {
		var query = window._content.document.getSelection();
		var revQuery = prompt("Search eBay", query);
		if (revQuery != null) {
		var myURL = "[URL unfurl="true"]http://search.ebay.com/search/search.dll?query="[/URL] + revQuery;
		openNewTabWith(myURL, null, null, true);
		}
}

Here's a bookmarklet I found that uses this feature
Code:
javascript:if(frames.length>0){F=' (Open frame in new window first.)'}else{F=''}Q=document.getSelection();if(!Q){void(Q=prompt('No text selected on page.'+F+'\n\nKeywords...?',''))};if(Q)location.href='[URL unfurl="true"]http://bookmarklets.com/moreinfo.phtml?q='+escape(Q)[/URL]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top