On the pages of my site is displayed in the iframe tag another page of the same site. Can you please tell me how to take the title of the page that is located in the iframe and place its value in the title of the page where this iframe tag is located (that is, the one in which it is loaded)? If I’m not confusing anything, js has a postMessage function that passes values between different documents without delay. But how to do it, I do not know. In principle, I don’t care how to implement it (be it js or php), as long as it works accurately and quickly.
- If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky ♦
|
1 answer
Suppose that we have such an iframe
:
<iframe id="otherPage" src="otherPage.php"></iframe>
You can pass the title
like this:
document.getElementById("otherPage").onload = function() { document.title = this.contentDocument.title; }
- I have this code with the transfer of tags in url using php: <iframe id = "ifr" src = "<? Php print $ url. $ _ SERVER ['QUERY_STRING'];?>" FRAMEBORDER = "0"> </ iframe> What page should I put your code on? I tried on the one in which the iframe is located, but there were no changes. id naturally changed. - Widgin
- @Widgin Yes, to the page where the
iframe
is located. If you have only oneiframe
, then you can usedocument.getElementsByTagName("iframe")[0]
instead ofdocument.getElementById("otherPage")
. - Peter Olson
|