How can I read the page title of the parent page from an iframe?

有些话、适合烂在心里 提交于 2019-12-24 08:41:10

问题


I have a page that calls another page(on another server) and I want that page to read the title from the parent page. Is this possible or is there some security issue with this?


回答1:


You cannot communicate across servers like that.




回答2:


You can use JavaScript to access the parent:

window.parent.document.title



回答3:


Call page A the caller page (with the JavaScript on it, the one requesting the title) and page B the page you want the title of.

Can you make a third page C (hosted on any server where A can access C and C can access B) which acts a go-between and servers up a JSON or XML request from the target page to the source page (where the JavaScript can call it?)? Page C could be any web app or CGI program capable of pulling down the HTML of page B and parsing it for the title, and then serving up the result in an AJAX friendly manner for page A to consume.

I suppose the usefulness of this depends on your goals and bigger-picture point of view of your project.



来源:https://stackoverflow.com/questions/1139632/how-can-i-read-the-page-title-of-the-parent-page-from-an-iframe

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!