如何从iframe中读取父页面的页面标题?

时间:2022-12-05 07:54:35

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?

我有一个页面调用另一个页面(在另一台服务器上),我希望该页面从父页面读取标题。这有可能还是存在一些安全问题?

3 个解决方案

#1


You cannot communicate across servers like that.

您不能在这样的服务器之间进行通信。

#2


You can use JavaScript to access the parent:

您可以使用JavaScript访问父级:

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.

调用页面A调用者页面(包含JavaScript,请求标题的页面)和页面B您想要标题的页面。

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.

你能创建第三个页面C(托管在A可以访问C和C可以访问B的任何服务器上),它作为中间人,并从目标页面向源页面提供JSON或XML请求(JavaScript可以在哪里叫它?)?页面C可以是任何Web应用程序或CGI程序,能够下拉页面B的HTML并解析它的标题,然后以AJAX友好的方式提供结果供页面A使用。

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

我认为这有用性取决于您的目标和项目的更大图景。

#1


You cannot communicate across servers like that.

您不能在这样的服务器之间进行通信。

#2


You can use JavaScript to access the parent:

您可以使用JavaScript访问父级:

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.

调用页面A调用者页面(包含JavaScript,请求标题的页面)和页面B您想要标题的页面。

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.

你能创建第三个页面C(托管在A可以访问C和C可以访问B的任何服务器上),它作为中间人,并从目标页面向源页面提供JSON或XML请求(JavaScript可以在哪里叫它?)?页面C可以是任何Web应用程序或CGI程序,能够下拉页面B的HTML并解析它的标题,然后以AJAX友好的方式提供结果供页面A使用。

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

我认为这有用性取决于您的目标和项目的更大图景。