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

js change iframe content

$(iframeSelector).contents().find('html').html(htmlContent);
Comment

js change iframe content

<iframe src="javascript:void(0);"></iframe>
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery carousel slide event 
Javascript :: tostring js 
Javascript :: render twice react 
Javascript :: class component react 
Javascript :: how to cut off decimals in javascript 
Javascript :: usestate wait for set 
Javascript :: jquery get fail 
Javascript :: add line number in javascript 
Javascript :: jest expect string to contain substring 
Javascript :: convert html to pdf using javascript 
Javascript :: initialize a map js 
Javascript :: merge arrays in javascript 
Javascript :: react comments 
Javascript :: Prevent safari loading from cache when back button is clicked 
Javascript :: javascript set value html element by class 
Javascript :: jquery find input and select 
Javascript :: javascript map to object 
Javascript :: enzynme not support react 17 
Javascript :: jstl library 
Javascript :: setImmediate() nodejs 
Javascript :: multiple conditions for JavaScript .includes() method 
Javascript :: como eliminar un elemento del dom con javascript 
Javascript :: chrome extension add css to page 
Javascript :: convert array of javascript into string with comma 
Javascript :: foreach loop google script 
Javascript :: jquery not equal 
Javascript :: onclick delete self 
Javascript :: select name get option value jquery 
Javascript :: react native swiper 
Javascript :: Get rid of white space around Angular Material modal dialog 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =