Page 1 of 1

Help with bookmark script and variable URL

Posted: Thu Jul 24, 2003 11:39 am
by Swede78
I have this javascript that I found a long time ago, that creates a bookmark link to add to "favorites" in IE4+. I'm trying to apply this to a dynamic page, where the URL may be different every time the page is loaded.

Here's the javascript:

<SCRIPT LANGUAGE="JavaScript">
var txt = "Bookmark Us!";
var url = "http://www.codebrain.com";
var who = "CodeBrain.com FREE JAVA";

var ver = navigator.appName;
var num = parseInt(navigator.appVersion);
if ((ver == "Microsoft Internet Explorer")&&(num >= 4)) {
document.write('<A HREF="javascript:window.external.AddFavorite(url,who);" ');
document.write('onMouseOver=" window.status=');
document.write("txt; return true ");
document.write('"onMouseOut=" window.status=');
document.write("' '; return true ");
document.write('">'+ txt + '</a>');
}else{
txt += " (Ctrl+D)";
document.write(txt);
}
</script>

I tried to combine PHP and this javascript to do this, but it doesn't work:

Code: Select all

<?php if( strstr($_SERVER['HTTP_USER_AGENT'],"MSIE") ) { ?>
<a href="javascript:window.external.AddFavorite(<?php echo 'http://www.website.com'.$URL.','.$PageTitle; ?>);">Bookmark this Page</a>
<?php } else { echo 'Bookmark this Page (Ctrl+D)'; } ?>
Any help would be appreciated. Thank you.

Posted: Thu Jul 24, 2003 11:49 am
by AVATAr
im gessing here.. dont you need to put the url between 's ? like

Code: Select all

<php echo '''http://www.website.com'.$URL.','.$PageTitle.''''; ?>

Posted: Thu Jul 24, 2003 12:17 pm
by Swede78
No, I don't think so. This is the output I get with my PHP code:

<a href="javascript:window.external.AddFavorite(http://www.website.com/page.php,Page Title);">Bookmark this Page</a>

So, it parses it as I'd expect. It looks like javascript doesn't get parsed like PHP or ASP. When you look at the source, it looks like the original code.

I have an idea. I'll post my idea if it works.

Posted: Thu Jul 24, 2003 2:12 pm
by Swede78
Here's what I came up with, which seems to work:

<?php
print <<< JAVA
<SCRIPT LANGUAGE="JavaScript">
var txt = "Bookmark This Page"
var url = "http://www.website.com/$CurrentURL"
var who = "$PageTitle"
var ver = navigator.appName
var num = parseInt(navigator.appVersion)
if ((ver == "Microsoft Internet Explorer")&&(num >= 4)) {
document.write('<A HREF="javascript:window.external.AddFavorite(url,who);"');
document.write('onMouseOver=" window.status=')
document.write("txt; return true ")
document.write('"onMouseOut=" window.status=')
document.write("' '; return true ")
document.write('">'+ txt + '</a>')
}else{
txt += " (Ctrl+D)"
document.write(txt)
}
</script>
JAVA;
?>