Get iframe DOM element based on its URL

I am using w3c boot time API. window.performance.getEntriesByType ("resource"); This gives a list of resources, including iframes. However, to get the embedded iframe resources, I need to get an iframe performance object that requires me to reference its "DOM node / element.

var myiframe2 = $("#myiframe2"); var myiframeContentWindow = myiframe2[0].contentWindow; var iframeContentPerf = myiframeContentWindow.performance; 

The question is how to get the iframe node link if all I know is the iframe url, that's all I know (I won't know the iframe id or name as opposed to the code example above).

Besides repeating the elements of the document and then filtering the fragments and comparing the iframe URL with the returned API of the resource, there is an easy way to get the iframe DOM node (given the iframe URL)

+6
source share
1 answer

If the iframe url hasn't changed, you can try to get it directly using CSS selectors using the exact url:

 document.querySelector('iframe[src="http://example.org"]'); 

If the URL changes, but you have a unique part for the iframe (which can identify a specific iframe):

 document.querySelector('iframe[src*="example.org/some/url"]'); 
+6
source

All Articles