Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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";
Comment

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();
Comment

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>
Comment

apply css to iframe content javascript

<script>
    setInterval(function(){
      document.getElementById("iframeId").classList.add('your-class')
    },500);
  </script>

Now you need to write css code with your class name. Thank you
Comment

js set iframe code

var html_string= "content";
document.getElementById('output_iframe1').src = "data:text/html;charset=utf-8," + escape(html_string);
Comment

PREVIOUS NEXT
Code Example
Javascript :: divisible by 3 javascript 
Javascript :: how to change a variables value in javascript 
Javascript :: convert string to unicode javascript 
Javascript :: javascript if object has key 
Javascript :: ERROR Invariant Violation: requireNativeComponent: "RNCViewPager" was not found in the UIManager. 
Javascript :: how to flip a Number in javascript 
Javascript :: max size input file html 
Javascript :: react prevent component from update once mounted 
Javascript :: axios default baseurl conditional environment 
Javascript :: node main 
Javascript :: string concatenation in js 
Javascript :: Round to at most 2 decimal places 
Javascript :: javascript change font color based on value 
Javascript :: how can ic get the id of div jq 
Javascript :: delete a node in dom javascript 
Javascript :: create an object array in js 
Javascript :: react router dom private route 
Javascript :: password confirmation using Joi 
Javascript :: js how to find element using id 
Javascript :: javascript highlight words 
Javascript :: js looping through array 
Javascript :: font awesome cdn svg with js 
Javascript :: validation select option jquery 
Javascript :: make multiple array in one array 
Javascript :: javascript tofixed no trailing zeros 
Javascript :: adb reverse USB debugging 
Javascript :: create new element 
Javascript :: bubble sort js 
Javascript :: jquery get 2nd child 
Javascript :: prisma query log 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =