Pages

Friday, July 4, 2008

The Operation aborted dialog in Internet Explorer 7

I encountered this dialog box error message yesterday when I was working on one of my projects.  What I was trying to do was to get the page to refresh when the user hits the Back button of the IE browser. What I did was to add a hidden field and manipulate the value of that html control on JavaScript onload event. I just put this code on header tag...

<script type="text/javascript">
        function addLoadEvent(func) {
            var oldonload = window.onload;
            if (typeof window.onload != 'function') {
                window.onload = func;
            } else {
                window.onload = function() {
                    if (oldonload) {
                        oldonload();
                    }
                    func();
                }
            }
        }
</script>

and the on the body tag the code is something like these...

<div id="targetContainer">
            <input type="hidden" id="refreshed" value="no">
</div>
  <div>
  <script type="text/Javascript">
            addLoadEvent(function()
            {
                if(document.getElementById('refreshed').value=='no')
                {
                    document.getElementById('refreshed').value='yes';
                }
                else
                {
                    document.getElementById('refreshed').value='no';
                    location.reload();
                }
            })
</script>
</div>

But still I was without success, as the dialog box randomly appeared.  I wonder what could the best solution be for this issue. I will post my solution once I figure out my mistake.