-2

I'm working on a solid-js application containing an iframe containing a website of my own design. The website contains links to pages of other domain names. I would like to know if it is possible for me to get the title of the current webpage contained in my iframe. I've read several stack overflow questions saying that it's impossible to get the title of a web page from another domain for security reasons. However, the web pages whose title I am looking for can be loaded in my iframe therefore allow the connection, that's why I wonder if in this case I can get their title. Here is the code of my iframe:

<iframe
  width="100%"
  height="1300"
  id="myiframe"
  src="https://gkwhelps.herokuapp.com"
></iframe>
James Z
  • 12,209
  • 10
  • 24
  • 44
gks
  • 191
  • 1
  • 4
  • 18

3 Answers3

0

The title of the web page contained in the iframe can be retrieved using the JavaScript function document.getElementById("iframeID").contentWindow.document.title.

Ron Adin
  • 49
  • 8
  • Thanks for the reply, I will try it. I suppose it allows to retrieve the title of any web page present in the iframe and not only the title of the web page contained at the base. – gks Aug 11 '22 at 23:48
  • have a great evening! – gks Aug 11 '22 at 23:49
0
$( "iframe" ).on('load',function() {
        document.title = document.getElementById("iframe").contentDocument.title;
});

This waits for the iframe to load then gets the iframe (must set the id to iframe) and then gets the title. Uses jQuery.

Gage
  • 89
  • 7
0

You will not be able to do it, unless it is a browser without CORS activated, or the page contained on the IFRAME is on the same domain/server.

You could investigate if you can allow CORS on your page or on the solid-js app.

JLq
  • 90
  • 1
  • 3
  • 8