Felix33
Feb 14th 2007, 4:53 pm
Hi everybody,
I need to find a script which would allow me to get the title (in between the HTML title tags) from a referring page. the website has lots of referring url's to it, and the idea is that when a user types in an url,
the first word of the title will be displayed on the page.
Now, I came up with a PHP script that works fine, problem is, that I can't use PHP, cause the redirects are all set to the .html pages and I can't change them. the script gets the referring URL, reads the page and extracts the title and breaks it down into words separated by whitespaces.
Is it possible to achieve the same with javascript?
here's the php:
<?php
$filesource = $_SERVER['HTTP_REFERER'];
$a = fopen($filesource,"r"); //fopen("html_file.html","r");
$string = fread($a,1024);
?>
<?php
if (eregi("<title>(.*)</title>",
$string, $out)) {
$outdata = $out[1];
}
//echo $outdata;
$outdatapart = explode( " " , $outdata);
echo $part[0];
echo $outdatapart[0];
?>
Any help would be greatly appreciated
I am not a JS expert, have been searching for a solution
have seen a couple of similar posts here, but didnt help me with my specific question ...
Thanks!
Felix
p.s.
I did find a function to find out and write out the referring page, just dunno how to go from here
head:
<script>
function loadRefURL (){
document.forms[0].theAddr.value = document.referrer;
</script>
body:
<script>
document.write( document.referrer );
</script>
I need to find a script which would allow me to get the title (in between the HTML title tags) from a referring page. the website has lots of referring url's to it, and the idea is that when a user types in an url,
the first word of the title will be displayed on the page.
Now, I came up with a PHP script that works fine, problem is, that I can't use PHP, cause the redirects are all set to the .html pages and I can't change them. the script gets the referring URL, reads the page and extracts the title and breaks it down into words separated by whitespaces.
Is it possible to achieve the same with javascript?
here's the php:
<?php
$filesource = $_SERVER['HTTP_REFERER'];
$a = fopen($filesource,"r"); //fopen("html_file.html","r");
$string = fread($a,1024);
?>
<?php
if (eregi("<title>(.*)</title>",
$string, $out)) {
$outdata = $out[1];
}
//echo $outdata;
$outdatapart = explode( " " , $outdata);
echo $part[0];
echo $outdatapart[0];
?>
Any help would be greatly appreciated
I am not a JS expert, have been searching for a solution
have seen a couple of similar posts here, but didnt help me with my specific question ...
Thanks!
Felix
p.s.
I did find a function to find out and write out the referring page, just dunno how to go from here
head:
<script>
function loadRefURL (){
document.forms[0].theAddr.value = document.referrer;
</script>
body:
<script>
document.write( document.referrer );
</script>