Thursday, January 12, 2012

Call to jQuery dialog will execute external Javascript!

I came across this while debugging jsp page. Totally took my few hours of scratching my head til bleed.

The gotcha is when included jsp imports javascript and if the jsp is within jQuery dialog, the imported javascript is also read by browser once.

Maybe easier to show the code

foo1.jsp



    

        /* NOTE: jQuery dialog import is omitted for simplicity */

        
    

    
        

Hello World!


foo2.jsp


    
         
    
    
    

alert.js

alert("alert");

What happen here is when the button is clicked, dialog is displayed but before that, alert message from alert.js is executed!

This proves that dialog section includes javascript, it will get executed

No comments:

Post a Comment