none
Google Translate JavaScript

    Question

  • This code works in Chrome. But in IE8 I get "null".

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


    What's the problem?

    Sunday, August 28, 2011 8:51 AM

Answers

  • Does changing the code to

    window.open(url, 'windowName', 'resizable=yes,left=0,top=0,width=' + window.screen.availWidth + ',height=' + window.screen.availHeight)

    improve the behaviour of the opened window?


    MVP Data Platform Development My blog
    • Marked as answer by a04 Monday, August 29, 2011 12:27 PM
    Monday, August 29, 2011 10:20 AM

All replies

  • Is that a bookmarklet that is supposed to open a new window trying to translate either the current text selection or the complete document with Google's translate service?

    Where do you get the null, in the current window? That means the window.open failed I think, perhaps due to popup blocking enabled.

    I tried the bookmarklet here with IE 9 on Windows 7 and it opened a window so you might want to check your IE settings and additionally an settings of additional security software that might block pop ups.


    MVP Data Platform Development My blog
    Sunday, August 28, 2011 11:24 AM
  • 1. Yes it is.

    2.  In the current window.

    3. I disable popup blocking and... it works but with problems:

    • The original window  is replaced by "[object]".
    • The new window works Ok, but I wanted it t be open as Maximized Window.
    Sunday, August 28, 2011 2:42 PM
  • 1. Yes it is.

    2.  In the current window.

    3. I disable popup blocking and... it works but with problems:

    • The original window  is replaced by "[object]".
    • The new window works Ok, but I wanted it t be open as Maximized Window.

    Put the code

     void 0

    at the end of your bookmarklet after the final semicolon that you have, that way the new window will not be replaced by [object].

    As for a maximized value, I don't think there is an option to have that. Check out the options the documentation http://msdn.microsoft.com/en-us/library/ms536651%28v=VS.85%29.aspx lists for the third argument, the feature string.


    MVP Data Platform Development My blog
    Sunday, August 28, 2011 3:17 PM
  • 1. It works. Thank You.

    2. I don't know to read syntax well. Can you Help me?

    Thank You.

    Sunday, August 28, 2011 5:26 PM
  • Well there is no option to have a maximized window. You can try whether

      window.open(url, 'windowName', 'left=0,top=0,width=' + window.screen.availWidth + ',height=' + window.screen.availHeight)

    suits your needs in the bookmarklet.


    MVP Data Platform Development My blog
    Sunday, August 28, 2011 5:54 PM
  • Almost done.

    The Window is Maximized but...

    The problem now is I can't resize the Window. I wanted a regular maximized window, that I can play with the size after.

    Do you have any solution for that?

    Thank You.

    Sunday, August 28, 2011 7:27 PM
  • Does changing the code to

    window.open(url, 'windowName', 'resizable=yes,left=0,top=0,width=' + window.screen.availWidth + ',height=' + window.screen.availHeight)

    improve the behaviour of the opened window?


    MVP Data Platform Development My blog
    • Marked as answer by a04 Monday, August 29, 2011 12:27 PM
    Monday, August 29, 2011 10:20 AM
  • Great. Thank you very much.

    Here is the code:

    javascript:var t = ((window.getSelection&&window.getSelection()) || (document.getSelection&&document.getSelection()) || (document.selection&&document.selection.createRange && document.selection.createRange().text));var e = (document.charset || document.characterSet);if (t!='') {window.open('http://translate.google.com/translate_t?text=' + t + '&hl = he&langpair=auto|he&tbb=1&ie=' + e,'newWin','resizable=yes,left=0,top=0,width=' + window.screen.availWidth + ',height=' + window.screen.availHeight);} else {window.open('http://translate.google.com/translate?u=' + escape(location.href) + '&hl = he&langpair=auto|he&tbb=1&ie=' + e,'newWin','resizable=yes,left=0,top=0,width=' + window.screen.availWidth + ',height=' + window.screen.availHeight);}; void 0
    


    But, I have to say that the opened window doesn't behave as normal. I can't edit the Url and the Favorites are missing, and sometimes I'm hearing 2 clicks instead 1 click when operating.

    Thank You

    Monday, August 29, 2011 12:27 PM
  • I want to keep the popup blocking enabled. How can I exclude this stuff from blocking?
    Saturday, October 08, 2011 9:55 PM