Get iframe url var url = document. com/en-us/library/ms536474(VS. The first method involves accessing the iframe object directly. Syntax document. 85). microsoft. The src attribute specifies the URL of the document to show in an iframe. aspx const iframeReference = document. //(i. com/home. load(function() { alert($(this). For instance, we write const url = document. URLReturn You can access the src property of the iframe but that will only give you the initially loaded URL. const iframe = document. contentWindow. html . This method assumes that you have access to the iframe element in your HTML code: const iframe = document. href property by using that we can access the current url. The src property sets or returns the value of the src attribute in an iframe element. src) : undefined; if (iframeUrl) { console. </script> </iframe> Beware also of "accessing a cross-origin frame" error. getElementById("iframeid"); . getElementById() method. getElementById("iframe"); Now, it has a contentWindow. warn("iframe with id iframe_id not found"); } In this guide, we'll walk through how to get the current URL of an iframe using JavaScript. e) http://www. get(0). To get current URL from an iframe with JavaScript, we can use the contentWindow. href; Here are two different methods to get the current URL in JavaScript. href); }); . 1. image. log("Voila: " + iframeUrl); } else { console. If the user is navigating around in the iframe via you'll need to use an HTA to solve the security problem. The string also includes the HTTP protocol such as ( http://). http://msdn. Now, it has a contentWindow. This will work only if they are in the same domain,protocol and port: else use : To get the current URL from a IFRAME, first we need to access the iframe inside the JavaScript by using the document. Using Document. getElementById("iframe_id"). const iframeReference = document. //get the ifram onload url of href . href; It simply doesn't give you the current url - but the url it started with. URL PropertyThe DOM URL property in HTML is used to return a string that contains the complete URL of the current document. location. To get the current URL from a IFRAME, first we need to access the iframe inside the JavaScript by using the document. getElementById('my-iframe'); const currentUrl = iframe. The domain has to be from the same origin to use the method of the following code: $('#myframe'). aspx. href property. getElementById("iframe_id"); const iframeUrl = iframeReference ? new URL(iframeReference. ggjpirdrhwnkwxknxvwdkmuaktmuulgryxhjffyagjpzwtzbs
close
Embed this image
Copy and paste this code to display the image on your site