How to call a parent window function from an iframe

0 votes

I want to call a parent window JavaScript function from an iframe.

<script>
    function abc()
    {
        alert("sss");
    }
</script>

<iframe id="myFrame">
    <a onclick="abc();" href="#">Call Me</a>
</iframe>

How to do that?

Sep 3, 2020 in Java-Script by kartik
• 37,490 points
350 views

1 answer to this question.

0 votes

Hello @kartik,

Using Window.postMessage()

This method safely enables cross-origin communication.

And if you have access to parent page code then any parent method can be called as well as any data can be passed directly from Iframe.

Hope it helps!!

Thank you!!

answered Sep 3, 2020 by Niroj
• 82,540 points

Related Questions In Java-Script

0 votes
1 answer

How to access PHP session variables from jQuery function in a .js file?

Hello @kartik, You can produce the javascript file ...READ MORE

answered Jul 7, 2020 in Java-Script by Niroj
• 82,540 points
106 views
0 votes
1 answer

How to show a different value from an input that what will be received as php?

Hello @kartik, You can't change the field's value ...READ MORE

answered Jul 7, 2020 in Java-Script by Niroj
• 82,540 points
1,150 views
0 votes
1 answer

How to pass an array as a function parameter in JavaScript?

Hello @kartik, Use: const args = ['p0', 'p1', 'p2']; call_me.apply(this, ...READ MORE

answered Sep 4, 2020 in Java-Script by Niroj
• 82,540 points
124 views
0 votes
1 answer

How to manage a redirect request after a jQuery Ajax call?

Hii kartik, You can resolved this issue like ...READ MORE

answered Apr 27, 2020 in Java-Script by Niroj
• 82,540 points
7,570 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,540 points
4,821 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,540 points
547 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,540 points
411 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,540 points
5,441 views
0 votes
1 answer

How to redirect parent window from an iframe action?

Hello @kartik, Use this: window.top.location.href = "http://www.example.com"; Will redirect ...READ MORE

answered Sep 2, 2020 in Java-Script by Niroj
• 82,540 points
962 views
0 votes
1 answer

How to access PHP session variables from jQuery function in a .js file?

Hello, You can produce the javascript file via ...READ MORE

answered Apr 29, 2020 in Java-Script by Niroj
• 82,540 points
4,459 views