i have a html file with iframe and button in it, Is there a way to add a javascript function inside the body of iframe after I click the button?. Here is my code. Thanks
<html>
<head>  
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
    <script>
        function callMe() { 
            var frame = $('iframe'),
            contents = frame.contents(),
            body = contents.find('body');
    var script2   = document.createElement("script");
    script2.type  = "text/javascript";
    script2.text  = " function setEmployeeId(){var employeeId = 0;};"            
    $(body).append(script2);
        };      
    </script>
    <title>sample</title>
</head>
<body>
        <iframe src="page2.html">           
        </iframe>
    <button onClick="callMe();">click</button>
</body>
</html>
The result I want is to be like this.
<html>
<head>  
    <title>sample</title>
</head>
<body>
        <iframe>
<html>
<head>  
    <title></title>
</head>
<body>
   <script>
function setemployeeId() {
var employeeId = 0;
};
</script>
</body>
</html> 
</iframe>       
</body>
</html>
 
     
    