My goal is to build a component in React with an iframe and be able to handle the click event on that iframe. However, my onClick event doesn't fire, only when I click on the parent div that is outside the scope of the child iframe it contains. Is there any solution to help me with this? Thanks.
export default function App() {
return (
<div className="App">
<div onClick={() => alert("Testing")}>
<iframe
src="https://google.com.vn"
title="stackoverflow"
style={{ width: "100%", height: "100%" }}
/>
</div>
</div>
);
}
My sandbox: https://codesandbox.io/s/onclick-on-parent-of-iframe-jjigu?file=/src/App.js