0

如果我有2個HTML頁面和我使用的iframe,我可以使用裏面嵌入了燈開關屏幕的iframe,如何從父定製控件元素調用java腳本函數?

window.parent.myfunction(); 

注調用父項的子功能js函數嵌入在他們(子頁面)的其他(父頁)內:無法在Chrome工作

我需要應用此在Visual Studio光開關

我使用iframe嵌入自定義的控制元素中的HTML頁面中光開關屏幕,我想從自定義控件調用JavaScript函數渲染使用它白色按鈕在iframe內(onclick)..我試過window.parent.myfunction();,但它沒有奏效。

自定義控件呈現

myapp.LaunchURL.BigCustom_render = function (element, contentItem) { 

    element.innerHTML += '<div id ="mycontent" style="width:100%; height: 100%;"> </div>"'; 
    document.getElementById("mycontent").innerHTML += 
     '<iframe src="page.html" id ="myframe" name = "myframe" style="width:100%; height:100%;"></iframe>'; 

    var iframe = $('iframe').contents(); 

    iframe.find('#h2id').text("change the text please"); 

    iframe.find('#A2').attr("value", "ok this works"); 

    myapp.activeDataWorkspace.ApplicationData.Students.load().then(
     function onComplete(result) { 
      var studentNames = ""; 
      result.results.forEach(function (student) { 
       //alert(student.Name); 
       studentNames += (student.Name + " "); 
      }); 

      // alert(studentNames); 

      iframe.find('#A1').attr("type", "text"); 
      iframe.find('#A1').attr("value", studentNames); 
     } 
     ); 


    function AlertOnChange() 
    { 

     alert("the student name changes"); 
    } 





    //to have the entire webpage 
    $("iframe").parent().parent().css("width", "100%"); 
    $("iframe").parent().parent().css("height", "1200px"); 

    //to eliminate the header if you want to 
    $("span").parent().parent().parent().parent().parent().css("width", "0px"); 
    $("span").parent().parent().parent().parent().parent().css("height", "0px"); 

}; 

的HTML頁面

<!DOCTYPE html> 
<html> 
<head> 
    <title>Dating Form</title> 
</head> 
<body> 


    <h2 id="h2id"> the students</h2> 
    <br /> 
    <br /> 
    <form> 

     <input type="button" value="Get Students" onclick="window.parent.AlertOnChange();"></input> 
     <br /> 
     <br /> 

     <input type="hidden" id="A1" name="A1" value="hidden" onchange="window.parent.AlertOnChange()"> Students Names </input> 
     <br /> 
     <br /> 

     <input type="text" id="A2" name="A2" value="text this text box"> textbox </input> 


    </form> 


    <script> 
     //function childAlertOnChange() 
     //{ 
     // //window.parent.AlertOnChange(); 
     //} 
    </script> 
</body> 
</html> 

此按鈕沒有反應和沒有做的事情ENY

the button don't do eny thing

回答

0

我定義了t之外的函數他自定義控件渲染和它的作品

這是我的代碼

var AppData; 


myapp.LaunchURL.BigCustom_render = function (element, contentItem) { 

    element.innerHTML += '<div id ="mycontent" style="width:100%; height: 100%;"> </div>"'; 
    document.getElementById("mycontent").innerHTML += 
     '<iframe src="page.html" id ="myframe" name = "myframe" style="width:100%; height:100%;"></iframe>'; 

    var iframe = $('iframe').contents(); 

    iframe.find('#h2id').text("change the text please"); 

    iframe.find('#A2').attr("value", "ok this works"); 

    //to have the entire webpage 
    $("iframe").parent().parent().css("width", "100%"); 
    $("iframe").parent().parent().css("height", "1200px"); 

    //to eliminate the header if you want to 
    $("span").parent().parent().parent().parent().parent().css("width", "0px"); 
    $("span").parent().parent().parent().parent().parent().css("height", "0px"); 

}; 



function AlertOnChange() { 
    alert("the student name changes"); 

    AppData.Students.load().then(
    function onComplete(result) { 
     var studentNames = ""; 
     result.results.forEach(function (student) { 
      //alert(student.Name); 
      studentNames += (student.Name + " "); 
     }); 

     // alert(studentNames); 
     alert(studentNames); 
     $('iframe').contents().find('#A1').attr("type", "text"); 
     $('iframe').contents().find('#A1').attr("value", studentNames); 
    } 
    ); 

} 



myapp.LaunchURL.created = function (screen) { 
    // Write code here. 
    AppData = myapp.activeDataWorkspace.ApplicationData; 
}; 
相關問題