Link to home
Start Free TrialLog in
Avatar of rodojohn
rodojohnFlag for Greece

asked on

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

Avatar of rodojohn
rodojohn
Flag of Greece image

ASKER

the webpage is in asp.net (c#)
Avatar of Rob
For what reason have you nested the JQuery functions?

eg.

jQuery(document).ready(function() {
    jQuery(function (jQuery) {
...
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.
Are you using noConflict because you ate using another framework or again because of their practice?
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.
What does this do :-

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


Is this page causing many call backs to the server?
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
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]
also it causes no call back to my server
That I understood. Sorry but it is almost 20:00 and it's cheese time. Back Monday.
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

BurnieP very Good  Proposal but unfortunatelly it didnt solve the IE problem :(
ASKER CERTIFIED SOLUTION
Avatar of rodojohn
rodojohn
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
help from the official jquery & googgle api reference