...

View Full Version : Void a Prompt if text is selected?



humanfly199
01-14-2007, 09:49 PM
Hi, will someone please help with this.

This will prompt 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 not sure how to put it in there. The bookmarklet below does this perfectly. Will someone help me please? :o


The Code..

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



A Bookmarklet I found that does what I want...


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='http://bookmarklets.com/moreinfo.phtml?q='+escape(Q)

ImperialSpider
01-15-2007, 05:20 AM
Hi, will someone please help with this.

This will prompt 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 not sure how to put it in there. The bookmarklet below does this perfectly. Will someone help me please? :o


The Code..

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



A Bookmarklet I found that does what I want...


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='http://bookmarklets.com/moreinfo.phtml?q='+escape(Q)
I think what you did here is you put in the "if-then" statement, but forgot to put in what happens in case that statement does not occur... What I recommend is to do what I call the "if-then-else" statement. An example...

If problem, then do this,
Else do that

This basically covers all areas, so if the problem exists, it does something to fix it, but if problem does not exist, it does something else (usually nothing)

If you need more help on this, look up "if else statements" on the internet.


Hope this helps,

Imperial Spider



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum