tags:

views:

29

answers:

2

Hi I'm looking for an API that retrieve page title in Javascript, for an address given.

Thanks

A: 

Javascript cannot access external document's titles

mplungjan
A: 

You can retrieve the title of the current window by using document.title:

<button onclick="alert(document.title);">show title</button>

You can how ever use an iframe for different pages provided that they are on the same domain:

<script>
   function iframeLoaded(iframe){
        alert(iframe.contentWindow.document.title);
   }

   function getTitle(){
        var url = "<some url here>";
        var htm = '<iframe src="'  + url + '" onload="iframeLoaded(this)"></iframe>';
        document.getElementById('loader').innerHTML = htm;
   }
</script>
<button onclick="getTitle()">get title</button>
<div id="loader" style="display:none">

</div>
jerjer
sorry, maybe I'm not explain very well I, just would mean If there's an API that can retrieve page title from external page (infact javascript access page only same domain) in javascript for example google have an api ajax that retrieve a favicon from external site.THANKS :)
in this case you may need to do it in server-side(an ajax-proxy perhaps)
jerjer