Horje
run javascript in iframe Code Example
how to get element in iframe using javascript
const iframe = document.getElementById("myIframe");

const iWindow = iframe.contentWindow;
const iDocument = iWindow.document;

// accessing the element
const element = iDocument.getElementsByTagName("p")[0];
element.style.color = "green";
Source: reactgo.com
use javascript to control iframe elements
<iframe id="myIFrame" src="thispage.html"
    width="100%" height="600"
    frameBorder="2">
</iframe>

// Get the iframe
const iFrame = document.getElementById('myIFrame');

// Let's say that you want to access a button with the ID `'myButton'`,
// you can access via the following code:
const buttonInIFrame = iFrame.contentWindow.document.getElementById('myButton');

// If you need to call a function in the iframe, you can call it as follows:
iFrame.contentWindow.yourFunction();
js set iframe src
<script type="text/javascript">
function iframeDidLoad() {
    alert('Done');
}

function newSite() {
    var sites = ['http://getprismatic.com',
                 'http://gizmodo.com/',
                 'http://lifehacker.com/']

    document.getElementById('myIframe').src = sites[Math.floor(Math.random() * sites.length)];
}    
</script>
<input type="button" value="Change site" onClick="newSite()" />
<iframe id="myIframe" src="http://getprismatic.com/" onLoad="iframeDidLoad();"></iframe>
run javascript in iframe
let script=document.createElement('script');
script.innerText=`your script`
document.querySelector('iframe').appendChild(script)
run javascript in iframe
var iframe = document.getElementById('frameID'),
    iframeWin = iframe.contentWindow || iframe,
    iframeDoc = iframe.contentDocument || iframeWin.document;

window.hello = function () {
    alert('hello from owner!');
};

$(iframeDoc).ready(function (event) {
    iframeDoc.open();
    iframeDoc.write('iframe here');
    iframeDoc.write('\<script>alert("hello from iframe!");\<\/script>');
    iframeDoc.write('\<script>parent.hello();\<\/script>');
    iframeDoc.close();
});
Source: jsfiddle.net




Javascript

Related
jquery remove duplicates from array Code Example jquery remove duplicates from array Code Example
javascript find all matches in array Code Example javascript find all matches in array Code Example
if statement inside a function in javascript Code Example if statement inside a function in javascript Code Example
Cursor.jsx:8 Uncaught TypeError: Cannot read properties of null (reading 'clientWidth') Code Example Cursor.jsx:8 Uncaught TypeError: Cannot read properties of null (reading 'clientWidth') Code Example
vuejs props declare prop with multiple types Code Example vuejs props declare prop with multiple types Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
8