javascript - How can I use XMLHttpRequest to grab the title of a page and return it to my page? -


i got basic understanding of ajax down, not sure if there way use read dom , send information used on page...

in specific case, links news stories being stored in database, , trying text between <a href> , </a> populated actual title of story.

any ideas? thanks

first of all, you'll need proxy on own server, because cross-domain requests not allowed. simple proxy echo page you, efficiency, should use regular expressions return page's title, want. example, in php:

$text = file_get_contents($_request['newspage']); preg_match("/(?<=\<title\>)[^\>]+/", $text, $matches); if(count($matches)) {      echo $matches[0]; } else {      echo "unknown title"; } 

it's easy use - send simple ajax request script newspage parameter, , put result link.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -