Home >Web Front-end >HTML Tutorial >How to add js function to iframe in page_html/css_WEB-ITnose
As the title says, I used an iframe to create an input box on the jsp page, but the iframe does not seem to support the onclick function. How can I add a function to this iframe to achieve the onclick effect? I hope God will give you some advice, thank you very much! Waiting online
If it is not cross-domain, you can access the page window object in the ifram through iframe.contentWindow, register its body or The click event of the document is enough;
If it crosses the domain, it will be difficult to do.
If it does not cross the domain, you can access the page window object in the ifram through iframe.contentWindow and register its body or document. Just click on the event;
If it is cross-domain, it will be difficult to do it
I don’t understand why you want to add a click event to the iframe. Cross-domain means responding to requests from different sites. Generally speaking, our web programs switch between different pages under one site, and these pages are all under the same server. If we talk about cross-domain, for example, if you want to embed a weather function in an iframe, but the weather data comes from the interface of an official data website of a certain national department, then this is cross-domain.
If it is not cross-domain, you can access the page window object in the ifram through iframe.contentWindow, and register the click event of its body or document;
If it is cross-domain, It’s very difficult
I don't understand why you want to add a click event to the iframe. Cross-domain means responding to requests from different sites. Generally speaking, our web programs switch between different pages under one site, and these pages are all under the same server. If we talk about cross-domain, for example, if you want to embed a weather function in an iframe, but the weather data comes from the interface of an official data website of a certain national department, then this is cross-domain.