Web Hosting - Free All Ebook PDF Download - Indian television shows news - Debt Consolidation - Debt Consolidation

PDA

View Full Version : get title(part) from referring URL - javascript instead of PHP


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>

nico_swd
Feb 14th 2007, 5:16 pm
Not possible with Javascript.

Felix33
Feb 15th 2007, 2:47 pm
Why should it not be possible???
I believe it is. After all there are JS ways to get referring URLs, readin g and writing files and string functions, I've been finding out that much, just trying to figure out how to put it together...

coolsaint
Feb 15th 2007, 5:40 pm
Not possible with javascript.

CBDealer
Feb 16th 2007, 11:48 am
Why couldn't you do it with JS? You'd have to load the page and then you could either grab the content of the title element through the DOM or you could write the page content to a string and regex for the title tags.

nico_swd
Feb 16th 2007, 12:05 pm
And how do you load external pages with Javascript? I don't think that's possible.

CBDealer
Feb 16th 2007, 3:02 pm
And how do you load external pages with Javascript? I don't think that's possible.

Load the page into a child window like an invisible iframe or a popunder.

Felix33
Feb 17th 2007, 9:46 pm
found some more info in the meantime, not sure if it will help me
(sorry I am not allowed to post links yet)

also I have no access to the referring pages, they are redirected in a frameset redirect to the html page I am working with, which is loaded into a frameset.
wasn't a problem with the PHP.
I tried to get to the title with
document.getElementsByTagName("title")[0].innerHTML = document.title;
trying to use on the the top.document.title
but that didn't work, cause the files are on different servers.
Starting to wonder if this can work...
to CBDealer,
I was thinking on s.th. like you are talking about -
As I am no JS expert - any code hints to how to load the page and write it to a string?
I am familiar with iframes, have thought about that too,
Thanks a million

nico_swd
Feb 18th 2007, 1:57 pm
You cannot access frames that don't come from your URL. This is not allowed for security reasons. Wouldn't it be easier if you'd just make apache parse your HTML files too?

Felix33
Feb 18th 2007, 2:30 pm
Hi Nico,
Just found out that that would be a possibility, would make everything so much easier!
Our server doesn't give us access to the .htaccess file, but it would be worth changing hosts.
I am just looking into that,
Thanks

nico_swd
Feb 18th 2007, 2:40 pm
Yes, plus it would work if the user has Javascript disabled. :)

Good luck...