Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 904
  • Last Modified:

Jquery google translate throws "A script on this page is causing Internet Explorer to run slow"

On a large page with many elements      running the attatched code in IE8 results in the message "A script on this page is causing Internet Explorer to run slow" that prompts to stop or continue the script.

1.tried     async:true but did nothing
<script type="text/javascript" >



             jQuery.noConflict();

             jQuery(document).ready(function () {
                 jQuery(function (jQuery) {


                     var jQuerydestLang;
                     var jQuerydestLang = null;
                     jQuery.translate(function () {
                         jQuery.fn.translateTo = function (destLang) { jQuery('#translateit').translate('english', destLang, {  not: ' #ctl00_Menu1_ctl06_HyperLink2,#ctl00_fname,#ctl00_ftel,#ctl00_femail,#fmessage  ' }); return true; };








                         jQuerydestLang = '<asp:Literal ID="Literal1" runat="server">null</asp:Literal>';

                         if (jQuerydestLang) { jQuery.fn.translateTo(jQuerydestLang};


                     });

                 })
             })

Open in new window

0
rodojohn
Asked:
rodojohn
  • 8
  • 3
  • 2
  • +1
1 Solution
 
rodojohnAuthor Commented:
the webpage is in asp.net (c#)
0
 
RobOwner (Aidellio)Commented:
For what reason have you nested the JQuery functions?

eg.

jQuery(document).ready(function() {
    jQuery(function (jQuery) {
...
0
 
rodojohnAuthor Commented:
its my first use of jquery & its implementation and i followd the wiki documentation http://code.google.com/p/jquery-translate/wiki/General , every exampe is nested and i dont know why exactly , but i followed their practise.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
RobOwner (Aidellio)Commented:
Are you using noConflict because you ate using another framework or again because of their practice?
0
 
rodojohnAuthor Commented:
i had troubles with the $ syntax wich was ambiguus in my page which i also use the Ajax .net control again having a $ , i was getting e.g .translate not a function although the translate script was loaded, so finally i deprecated for this site the $ with ading the NoConflict.
0
 
BigRatCommented:
What does this do :-

 jQuerydestLang = '<asp:Literal ID="Literal1" runat="server">null</asp:Literal>';


Is this page causing many call backs to the server?
0
 
rodojohnAuthor Commented:
this line sets the selected language serverside and is to keep the language alive through the site

literal generates no code and i set the inside e.g. fr

which becomes jQuerydestLang = 'fr';

it works fine
0
 
BigRatCommented:
OK, fair enough. The problem is that Script runs on eth browsers GUI thread and when it spends too much time another thread suspends operation and produces the message box. Is it absolutely necessary to use the functions as such, since each instatiation causes an execution context to be created and destroyed? That is can't the functions simple be static and passed as reference instead of as text?

[When you write x = function() {.......}; x gets set to the text of the function. When one does x(...) the interpreter calls the parser, parses the script, creates the execution context and executes the function. When you write function abc(...) {...}    x=abc; then the function pointer is passed, there is no parsing and no execution context needs to be created]
0
 
rodojohnAuthor Commented:
also it causes no call back to my server
0
 
BigRatCommented:
That I understood. Sorry but it is almost 20:00 and it's cheese time. Back Monday.
0
 
BurniePCommented:
Hi,

I saw two things, maybe it is the cause of your problem or maybe not.

First,  on line 25 of your first post :

if (jQuerydestLang) { jQuery.fn.translateTo(jQuerydestLang};

You are missing a ')'. it should be :
if (jQuerydestLang) { jQuery.fn.translateTo(jQuerydestLang)};

Next, the way I read your code, you are doing document.ready twice.

You start with these two lines :

jQuery(document).ready(function () {
                 jQuery(function (jQuery) {

Which to me is the same thing but written differently.  I have simplified your function in the code below.  Worth a shot trying.


<script type="text/javascript" >
  jQuery.noConflict();
  jQuery(document).ready(function () {
    var jQuerydestLang = null;

    jQuery.translate(function () {
      jQuery.fn.translateTo = function (destLang) { jQuery('#translateit').translate('english', destLang, { not: ' #ctl00_Menu1_ctl06_HyperLink2,#ctl00_fname,#ctl00_ftel,#ctl00_femail,#fmessage  ' }); return true; };
      jQuerydestLang = '<asp:Literal ID="Literal1" runat="server">null</asp:Literal>';

      if (jQuerydestLang) { jQuery.fn.translateTo(jQuerydestLang) };
    });
  });
</script>

Open in new window

0
 
rodojohnAuthor Commented:
BurnieP very Good  Proposal but unfortunatelly it didnt solve the IE problem :(
0
 
rodojohnAuthor Commented:
On some pages that can happen, just use the async:true option! It will take more time but won't freeze the browser. You can probably set it to false on other browsers if they don't complain about this. Also, you can try the jQuery('#translateit').translateTextNodes() method instead of jQuery('#translateit').translate().
Delete comment
Comment 3 by rodoj...@gmail.com, Today (moments ago)
async:true; didnt worked but translateTextNodes() worked fine, no slow script message now

http://code.google.com/p/jquery-translate/issues/detail?id=63
0
 
rodojohnAuthor Commented:
help from the official jquery & googgle api reference
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 8
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now