-1

Yesterday I encountered an interesting issue with Internet Explorer. A script runs perfectly on Chrome, Firefox, Safari, but with Internet Explorer 11 it doesn't do anything. If I open the debugger it runs smoothly and everything is as it should, but the moment I close the debugger it stops working and I have no idea why is this. My first thought was the IE extensions, but I disabled them to no veil. I tried running in safe-mode, with admin rights, but nothing seems to work.

To summarize everything: IE - script runs ONLY while the debugger is On. No error is produced, it just doesn't work.

I would be really glad for any ideas what can I do regarding this. Thank you in advance.

--------------EDIT--------------- Here is the script that doesn't run.

        for (var i = 0; i < AllStrategyGrids.length; i++) {
                try {
                    isChange = true;
                    var data = $("#objectives").data("kendoGrid").select().data();
                    if (AllStrategyGrids[i].ID == data.uid) {
                        var jsonData = new Object();
                        jsonData.StrategicID = "1";
                        jsonData.ObjectiveID = $("#ObjectiveID").val();
                        jsonData.HeaderID = "00000000-0000-0000-0000-000000000000";
                        jsonData.PeriodID = "00000000-0000-0000-0000-000000000000";
                        jsonData.Strategic = "Please enter strategic";
                        jsonData.TaskStatus = "";
                        jsonData.TaskStatusID = "1";
                        jsonData.Position = "";
                        jsonData.Sorted = "1";
                        jsonData.SessionID = "00000000-0000-0000-0000-000000000000";
                        tmpGrid = AllStrategyGrids[i].Grid.data("kendoGrid");
                        var dataRows = tmpGrid.items();
                        var rowIndex = dataRows.index(tmpGrid.select());
                        $.ajax({
                            url: "CreateStrategy",
                            type: 'POST',
                            data:
                                    {
                                        strategics: jsonData,
                                        VersionID: $("#VersionUID").val(),
                                        index: rowIndex
                                    },
                            success: function () {
                                tmpGrid.dataSource.read();
                            }
                        });
                    }
                } catch (e) { }
            }
user2227904
  • 679
  • 1
  • 8
  • 27
  • What is the script? I know that if you attempt to do something like `console.log` with the debugger closed, it would throw an error since the console object doesn't exists at that point in time – Populus Mar 17 '15 at 22:10
  • This questions has been asked many times on SO and there are loads of articles on the net on this. Please try to do some small research before asking questions – makeitmorehuman Mar 17 '15 at 22:43
  • XGreen, if you think the issue is the same as the others why don't you at least post a link to the questions you are referring to? You aren't making positive contribution, but stating something that you don't backup. – user2227904 Mar 18 '15 at 09:29

2 Answers2

3

Just a guess, this is likely because you have a console.log in that script and in IE the console object doesn't exist if your debugger is closed... we've all be there :)

An easy fix is the just add small shim as early on in your site as you can.. it won't do a thing on any browsers except IE and will just stop the execution error that probably blocking your other JS code from running...

   <script>
      if(!console)console={log:function(){}};
   </script>

a more robust solution here :

'console' is undefined error for Internet Explorer

---- EDIT

Okay one thing i can see from your code is that you're going to fail silently because you've used a try catch but do nothing with it. This is going to catch any exception you are having (blocking it from reaching your window thus making it seem like you have no errors). I would perhaps alert the error message at the very least while testing (so you don't need to open Debugger) and see if anything is thrown...

I'd be suspecting your ajax request myself.. that or an undefined in IE8.. so add some logging alerts (brute force i know) to test your assumptions at certain points e.g.

alert("Reach here and data="+data);

Alternatively, i can also see that your ajax request has no callbacks for unsuccessful which might be good idea to add to your call. It might be that the success isn't calling for some reason...

                    $.ajax({
                            url: "CreateStrategy",
                            type: 'POST',
                            data:
                                    {
                                        strategics: jsonData,
                                        VersionID: $("#VersionUID").val(),
                                        index: rowIndex
                                    },
                            success: function () {
                                tmpGrid.dataSource.read();
                            }
                        })
                        .fail(function() {
                           alert( "error" );
                           //handle a failed load gracefully here
                        })
                        .always(function() {
                           alert( "complete" );
                           //useful for any clean up code here
                        });

Final food for thought.

Since you're checking the DOM for an item, and i have no idea when this code is called but just in case its called directly AFTER a page reload..and lets assume something in IE isn't ready at 'that' point, it might be the DOM isn't ready to be queried yet? Try executing this code when the DOM is ready.. lots of ways to achieve this $.ready , setTimeout(f(){},1) or vanilla... but you get the idea..

Community
  • 1
  • 1
  • Thank you for the solution, but this is not really the case. I have console.log on other functions which work great, but this one doesn't use it. See update in the question for script details – user2227904 Mar 18 '15 at 07:18
  • Tricky, because your not able to recreate the issue while the debugger is open, might i suggest then you create a log output div of sorts.. then override your log function to write to this instead. e.g. 'console.log = function(s){ getElementById('logout').append(s);}' You could also look at maybe catching the error object yourself and writing that out into this div too? 'window.onerror=function(e){ console.log(e.message) '} – Kevin C Jones Mar 18 '15 at 23:59
1

Note: Debugging Script with the Developer Tools: MSDN

To enable script debugging for all instances of Internet Explorer, on the Internet Options menu, click the Advanced tab. Then, under the Browsing category, uncheck the Disable script debugging (Internet Explorer) option, and then click OK. For the changes to take effect, close all instances of Internet Explorer then reopen them again.

Travis Clarke
  • 5,951
  • 6
  • 29
  • 36