从角度Iframe捕获点击事件

时间:2019-02-19 06:39:44

标签: javascript jquery angular iframe

在这里,我想捕获事件从子Iframe到父Iframe的特定功能。可以给我一些例子吗?

如果我的子iframe中有一个click事件,我想将该事件称为父iframe按钮(尤其是事件)

 <!DOCTYPE HTML>
    <html>
    <head>
        <title>
            Iframe test
        </title>

</head>
<meta charset='utf-8'>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
<style>
.name{
    font-family: monospace;
}
</style>
<script type="text/javascript">
    var iframe = $("C:Users/ajay.venkatesh/Desktop/IframeTEst1.html").contents();
    console.log("Iframe working");
    iframe.find('onloadFunction()').click(function(event){
   console.log('work fine');
});
</script>

<body>
<iframe src="C:\Users\ajay.venkatesh\Desktop\IframeTEst1.html"></iframe>
<h1 class="name"> Ajay Venkatesh</h1>
<button onclick="onloadFunction()"> LOAD</button>
</body>
</html> 

孩子

<!DOCTYPE html>
<html>
<head>
    <title>

    </title>
</head>
<body>
<script type="text/javascript">
    function onloadFunction(){
        // alert("Onload for the button");
        console.log("onload event")
    }

    function onloadPrompt(){
        // prompt("test Prompt");
        console.log("onload prompt event")
    }
</script>
<button onclick="onloadPrompt()"> PROMPT </button>
<button onclick="onloadFunction()"> LOAD </button>

</body>
</html>

0 个答案:

没有答案