Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Void a Prompt if text is selected?

    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?


    The Code..
    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...

    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='http://bookmarklets.com/moreinfo.phtml?q='+escape(Q)
    Last edited by humanfly199; 01-14-2007 at 10:11 PM.

  • #2
    Regular Coder
    Join Date
    Jan 2004
    Location
    San Antonio, TX
    Posts
    131
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by humanfly199 View Post
    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?


    The Code..
    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...

    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='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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •