Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

More of a script modification than of a script creation : opening it in a new tab

Hi,

I have a script I use as a bookmarklet and what I'd wish is that the result opens in a new tab instead of the current one.
It's a basic script intended to Google Translate either highlighted text if applicable otherwise the whole page.
Works OK except that I'd prefer the Google Translated page to appear in a new tab.

Here it is :

javascript:var%20t=((window.getSelection&&window.getSelection())||(document.getSelection&&document.getSelection())||(document.selection&&document.selection.createRange&&document.selection.createRange().text));var%20e=(document.charset||document.characterSet);if(t!=''){location.href='https://translate.google.com/translate_t?text='+t+'&hl=en&langpair=auto|en&tbb=1&ie='+e;}else{location.href='https://translate.google.com/translate?u='+escape(location.href)+'&hl=en&langpair=auto|en&tbb=1&ie='+e;};

Many thanks :)

Comments

  • Instead of

    location.href = URI;

    try

    window.open(URI, '_blank');

    As long as you normally divert new windows to a new tab instead, that should work.
  • Thanks, Jefferson Scher, for your help.

    I tried replacing
    location.href = URI;
    with
    window.open(URI, '_blank');
    and indeed the result opened in a new tab, but the original (current tab) was blankened with only the mention of javascript at the top ...

    javascript:var%20t=((window.getSelection&&window.getSelection())||(document.getSelection&&document.getSelection())||(document.selection&&document.selection.createRange&&document.selection.createRange().text));var%20e=(document.charset||document.characterSet);if(t!=''){window.open('https://translate.google.com/translate_t?text='+t+'&hl=en&langpair=auto|en&tbb=1&ie='+e,'_blank');}else{window.open('https://translate.google.com/translate?u='+escape(location.href)+'&hl=en&langpair=auto|en&tbb=1&ie='+e,'_blank');};

    Maybe have I incorrectly replaced the setting?
    But your suggestion got me on the right path, and I remembered another bookmarklet I had which opens result in a new tab, with
    void(open((URI));

    I have the following which runs fine : original tab is preserved, result opens in a new tab :

    javascript:var%20t=((window.getSelection&&window.getSelection())||(document.getSelection&&document.getSelection())||(document.selection&&document.selection.createRange&&document.selection.createRange().text));var%20e=(document.charset||document.characterSet);if(t!=''){void(open('https://translate.google.com/translate_t?text='+t+'&hl=en&langpair=auto|en&tbb=1&ie='+e));}else{void(open('https://translate.google.com/translate?u='+escape(location.href)+'&hl=en&langpair=auto|en&tbb=1&ie='+e));};

    Thanks again, because the fact is I had no clue where to even start from (I couldn't "conceptualize" the process). I'm no coder!
    Now i'll know better how to dig in the stuff!!
  • Don't you want to try this plugin?
    Tab Mix Plus
    tabmix.jpg
    307 x 139 - 8K
Sign In or Register to comment.