How to detect current iframe url?


india joleti

I wrote a html code to initialize the iframe with another website.

My domain name is for example:

www.mydomain.com/Index.html

at this

 <iframe src = "www.anotherdomain.com/pages/firstPage.html"/>

I want to detect the full new src url whenever the iframe gets a new url. The iframe text contains links to other pages within the initialization page. Is it possible and legal to do the job? thanks. Any help is appreciated.

I guess this involves a cross-origin issue, but is there a way around it?

Updates

i try to get the answer

 document.getElementById("myIframeId").src

Load event at frame. But it keeps showing the src used on initialization. It doesn't show the updated src.

document.getElementById("myIframeId").contentWindow.location.href

gives a security error that the http frame is trying to access https inside the iframe. Protocol mismatch.

I set my localhost to SSL and use https, but the requests are blocked. I do not know why

Charlie

I disagree with the answer suggesting that you use "src" to detect the current url of the iframe. It just doesn't give your current URL - it's the URL that starts with it.

The domain must be from the same origin in order to use the method of the following code:

$(document).ready(function() {
  $('#myframe').load(function() {
    alert($(this).get(0).contentWindow.location.href);
  }); 
});

If the domains are from different origins - but you have access to both (or both belong to you), you can use the iFrame's window.postMessagefunctions and contentWindowproperties to send the data for the parent page to display when the new page loads.

Here is a tutorial about this : http://javascript.info/tutorial/cross-window-messaging-with-postmessage

And, if the domain in the iFrame is completely unfamiliar, one way I can think of is to load that domain into a server-side script, and get it to render this data with the changed link. You can now call this script in an iFrame and use the attribute contentWindow.location.hrefon every load .

Related


How to detect current iframe url?

india joleti I wrote a html code to initialize the iframe with another website. My domain name is for example: www.mydomain.com/Index.html at this <iframe src = "www.anotherdomain.com/pages/firstPage.html"/> I want to detect the full new src url whenever the

How to detect current iframe url?

india joleti I wrote a html code to initialize the iframe with another website. My domain name is for example: www.mydomain.com/Index.html at this <iframe src = "www.anotherdomain.com/pages/firstPage.html"/> I want to detect the full new src url whenever the

How to detect current iframe url?

india joleti I wrote a html code to initialize the iframe with another website. My domain name is for example: www.mydomain.com/Index.html at this <iframe src = "www.anotherdomain.com/pages/firstPage.html"/> I want to detect the complete new src url whenever

How to detect iframe url jumping to another url

Yang Jian| I have a page login.php using iframe "src= http: //def.com/login ". My domain is example.com. After logout, the def.com jumps to http://def.com/home I want my page to jump from http://def.com/home to the iframe URL of my page http://example.com/logi

How to detect iframe url jumping to another url

Yang Jian| I have a page login.php using iframe "src= http: //def.com/login ". My domain is example.com. After logout, the def.com jumps to http://def.com/home I want my page to jump from http://def.com/home to the iframe URL of my page http://example.com/logi

How to detect current URL in view method

username I am creating a form for an entity and I need to omit some fields when creating the entity compared to when editing the entity. What should I do? When building a form for creation, should I have a form and omit the fields? Or is there another way? E.g

How to detect part of current url using jquery?

peace love Is it possible to detect a value from the current URL with jquery? E.g: http://example.com/home.php?name=john From this url, I need to know name == john: $(document).ready(function() { if (window.location.name == john) alert("my name

How to detect current URL in view method

username I am creating a form for an entity and I need to omit some fields when creating the entity compared to when editing the entity. What should I do? When building a form for creation, should I have a form and omit the fields? Or is there another way? E.g

How to detect current URL in view method

username I am creating a form for an entity and I need to omit some fields when creating the entity compared to when editing the entity. What should I do? When building a form for creation, should I have a form and omit the fields? Or is there another way? E.g

How to detect part of current url using jquery?

peace love Is it possible to detect a value from the current URL with jquery? E.g: http://example.com/home.php?name=john From this url, I need to know name == john: $(document).ready(function() { if (window.location.name == john) alert("my name

How to detect current URL in view method

username I am creating a form for an entity and I need to omit some fields when creating the entity compared to when editing the entity. What should I do? When building a form for creation, should I have a form and omit the fields? Or is there another way? E.g

How to detect if an iframe is loaded?

rouge: I'm trying to check if an iframe has loaded after the user clicked a button. I have got $('#MainPopupIframe').load(function(){ console.log('load the iframe') //the console won't show anything even if the iframe is loaded. }) HTML <button id='cl

How to detect iFrame in Xpages

Jack Pete Tilly I'm trying to render a panel based on whether the xpage is loaded in an iFrame. my code looks like this <xp:panel rendered="#{javascript:return window.self != window.top;}"> </xp:panel> But I got an error. Script interpreter error, line=1,

How to detect if an iframe is loaded?

rouge: I'm trying to check if an iframe has loaded after the user clicked a button. I have got $('#MainPopupIframe').load(function(){ console.log('load the iframe') //the console won't show anything even if the iframe is loaded. }) HTML <button id='cl

How to detect iFrame in Xpages

Jack Pete Tilly I'm trying to render a panel based on whether the xpage is loaded in an iFrame. my code looks like this <xp:panel rendered="#{javascript:return window.self != window.top;}"> </xp:panel> But I got an error. Script interpreter error, line=1,

How to detect if an iframe is loaded?

rouge: I'm trying to check if an iframe has loaded after the user clicked a button. I have got $('#MainPopupIframe').load(function(){ console.log('load the iframe') //the console won't show anything even if the iframe is loaded. }) HTML <button id='cl

Detect access denied to iframe url

winter I'm trying to check the url of an iframe, but I just realized that I don't need the actual url, just the information if the url is within my own domain. I think I can use document.getElementById("frameid").documentWindow.location.href It will return an

How to get current page loaded url from iframe

User 4082518 I'm using an iframe to load faroo.com as the default src in the frame when I search and move to other webpages that use Faroo. But still in the iframe src its showing faroo.com is just the url i want to capture the page that is loaded in the ifram

How the user retrieves the current iFrame URL (cross domain)

Cyril Duchon-Doris TL;DR: How can a user copy the current URL of an iFrame (cross-domain)? I want to insert an iFrame in my domain's webpage to be able to browse other partner websites (different domains). When a user finds a page he is interested in, he needs

How to get current page loaded url from iframe

User 4082518 I'm using an iframe to load faroo.com as the default src in the frame when I search and move to other webpages that use Faroo. But still in the iframe src its showing faroo.com is just the url i want to capture the page that is loaded in the ifram

How the user retrieves the current iFrame URL (cross domain)

Cyril Duchon-Doris TL;DR: How can a user copy the current URL of an iFrame (cross-domain)? I want to insert an iFrame in my domain's webpage to be able to browse other partner websites (different domains). When a user finds a page he is interested in, he needs

How to get current page loaded url from iframe

User 4082518 I'm using an iframe to load faroo.com as the default src in the frame when I search and move to other webpages that use Faroo. But still in the iframe src its showing faroo.com is just the url i want to capture the page that is loaded in the ifram

How to get url of current page from iframe and display on browser

Karage Kinki I have two domains. One for selling products https://sellproducts.com and the other for selling product documentation https://docs.product.wiki In https://sellproducts.com I have a page called docs ( https://sellproducts.com/docs ) which I use ifr

Get current URL from IFRAME

Chris: Is there an easy way to get the current url from an iframe? Viewers will browse multiple sites. I'm guessing I'll use something in javascript. kkyy : For security reasons, you can only get that url as long as the content of the iframe and the referencin

Get current URL from IFRAME

Chris: Is there an easy way to get the current url from an iframe? Viewers will browse multiple sites. I'm guessing I'll use something in javascript. kkyy : For security reasons, you can only get that url as long as the content of the iframe and the referencin

How to detect error 404 in iframe?

Christopher: My webpage uses iframes to collect content from other pages. All pages are on the same domain. On the main page, is there a way to confirm that all iframes are loaded and there are no 404 errors? Tony Chiboucas: Status exists only in response head

How to detect error 404 in iframe?

Christopher: My webpage uses iframes to collect content from other pages. All pages are on the same domain. On the main page, is there a way to confirm that all iframes are loaded and there are no 404 errors? Tony Chiboucas: Status exists only in response head

How to detect when an iFrame is fullscreen?

near-point I have a document embedded in my website using iFrames. iFrame is from Box.com Document Viewer. iFrames have their own built-in fullscreen button. The fullscreen button is in an iFrame, so I can't attach a click event listener to the button. I added

How to detect error 404 in iframe?

Christopher: My webpage uses iframes to collect content from other pages. All pages are on the same domain. On the main page, is there a way to confirm that all iframes are loaded and there are no 404 errors? Tony Chiboucas: Status exists only in response head