Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows 8 share target crashing with JQuery

I'm developing an app that receive contente (URI) and I'm testing it with IE10 sharing.

The problem is that my elements (span, divs or buttons) that have onclick event handler associated, closes the sharing panel in the second click. The second click in the window on any element causes the crash.

I've tested the code running the page as the default page of the app, and everything works fine. This undesired behavior occurs only on share panel.

After some time of manual debugging, I found the piece of code that is causing the crase: The Jquery lib. If Jquery is presente in the page, it causes crash in share panel.

Is not possible to debug this using Visual Studio because this crash occurs only I don't have the debugger attached. With the debugger attached to it, everything works fine.

Someone can help on this? See my simple page below

<!DOCTYPE html>
<html>

    <head>
        <title></title>
        <!-- WinJS references -->
        <script src="//Microsoft.WinJS.0.6/js/base.js"></script>
        <script src="//Microsoft.WinJS.0.6/js/ui.js"></script>
        <script src="/js/default.js" type="text/javascript"></script>
        <script src="/js/jquery-1.7.2.js" type="text/javascript"></script>
        <script>
            var curr;

            function test() {
                if (curr) {
                    curr.className = "cls1";
                }

                curr = event.srcElement;
                curr.className = "cls2";
            }
        </script>
        <style>
            .cls1 {
                background-color: #f00;
                cursor: pointer;
            }
            .cls2 {
                background-color: #0094ff;
                cursor: pointer;
            }
        </style>
    </head>

    <body>
        <h1>Share</h1>
        <br />
        <div onclick="test();" class="cls1">Button</div>
        <div onclick="test();" class="cls1">Button</div>
    </body>

</html>

Thanks!

like image 735
Murilo Maciel Curti Avatar asked Mar 30 '12 18:03

Murilo Maciel Curti


1 Answers

try this instead:

<div onclick="javascript:test(); class="cls1">Button</div>

with optional:

/* Your own code is good enough but i wanted to create another point of view */
var curr;

function test() {
    curr = event.srcElement;
    if ($(curr).hasClass("cls1")) {
        $(curr).removeClass("cls1")
        $(curr).addClass("cls2")
    }
});

or another way to do it:

$(document).ready(function () {
    $("div").each(function () {
        $(this).click(function () {
            if ($(this).hasClass("cls1")) {
                $(this).removeClass("cls1")
                $(this).addClass("cls2")
            }
        });
    });
});

Please inform me if you can see any changes. I answered this way (blindly) cause only think make sense here is having trouble with js and i wonder while u got jquery lib why dont you use it? well thats another question offcourse. If you think my answer doesnt fit your question than please try to give us as much information as you can to solve this issue.

like image 161
Berker Yüceer Avatar answered Nov 03 '22 08:11

Berker Yüceer