最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I read the page title of the parent page from an iframe? - Stack Overflow

programmeradmin2浏览0评论

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?

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?

Share Improve this question edited Jul 16, 2009 at 19:11 Motti 115k56 gold badges194 silver badges274 bronze badges asked Jul 16, 2009 at 19:01 Ryan DetzelRyan Detzel 5,59910 gold badges38 silver badges50 bronze badges 1
  • I need it for an ad. A website is running our ads in a iframe but the ad needs access to the page title to properly target. So, the page and iframe are on their server then they execute the ad script in the iframe so I need to grab the parent's title. Possible? – Ryan Detzel Commented Jul 16, 2009 at 19:32
Add a ment  | 

3 Answers 3

Reset to default 2

You cannot municate across servers like that.

You can use JavaScript to access the parent:

window.parent.document.title

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.

发布评论

评论列表(0)

  1. 暂无评论