Search code examples
javascripthtmljqueryiframeembed

Get src attribute(video link) from an iframe on a separate(not owned by me) domain into my own website(dynamically)


Was wondering if it would be possible to aquire the src attribute from an iframe. This website though appears to have dynamically created said iframe through javascript with the video link in question. Is it still possible?

Through using the jQuery function $.get to aquire the HTML of the website, I soon learnt that the iframe was not placed right in the HTML. With my current knowledge I could not find a solution to get to the src attribute of a non-HTML created iframe.

The ultimate goal of me making this question is to dynamically be able to search for a video which is embeded on a website(have been completed), and then copy said embed(video) to my own(not affiliated) website to be used temporarily. The embeds in question on said website are not meant to be used in this sort of way and does therefore not have userfriendly-method to accomplishing this(tried searching for it but to no avail).

Thank you to anyone who might be able to help me, and I also do not care about whether I'd have to include a separete library/api to complete this request, as results are the onlything that matters as of now.


Solution

  • sure @CluelessMinion,

    you can programmatically get the src of an iframe with the following JS:

    document.getElementById('IFRAMEID').src;
    

    where IFRAMEID is (obviously) the ID of the iframe (can be substituted for ClassName, TagName, etc, if ID is not given). See document.getElementsByClassName (https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByClassName)

    See document.getElementsByTagName (https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByTagName)

    If this doesn't work for you, feel free to tell me the specific error message, and I'll do my best to find something that DOES work.