PDA

View Full Version : set to homepage



smoketer
02-14-2006, 03:15 AM
is there anyway to do the following?

1 - load the "set homepage to:______" script automatically
2 - remember what the user selected and next time NOT load the script

http://www.dynamicdrive.com/dynamicindex9/addhome.htm

eg:. John Doe comes to the site, is immediately prompted to set the homepage, and selects either "YES" or "NO". John Doe will never get prompted again.

Twey
02-14-2006, 11:09 AM
Try:

<!--[if gte IE 5]>
<p id="fish"></p>
<script type="text/javascript">
if(document.cookie.indexOf("askedHomePage=true;") == -1) {
if(window.confirm("Set your homepage to " + window.location.href + "?")) {
var f = document.getElementById("fish");
f.style.behavior = "url(#default#homepage)";
f.setHomePage(window.location.href);
}
document.cookie += "askedHomePage=true;";
}
</script>
<![endif]-->Quite unreliable, but so's the whole setHomePage() thing, so I guess it doesn't matter.

jscheuer1
02-14-2006, 12:09 PM
I think you would want:

<!--[if gte IE 5]>

for IE5 and later, your conditional comment will select IE5 only. Not vouching for or against the rest of the code.

Just my 2 cents:

I think the whole Homepage idea is obnoxious. Conditional comments are neat though.

Twey
02-14-2006, 12:13 PM
Guess who missed the "+" on the script ratings. :o
I'm obviously not awake yet. Give me time :p

I think the whole Homepage idea is obnoxious.Hey, it's only IE, so I don't mind :p If Microsoft put things like this into their browser, they deserve to have people migrate away from it; if people don't migrate away from it, they deserve to have delightful little jewels like this in their browser.
Conditional comments are neat though.But not as neat as Microsoft actually making IE standards-compliant, so we don't have to use completely different code for it in the first place.

jscheuer1
02-14-2006, 12:34 PM
I've got an idea. Let's start a long winded, at times heated, discussion of the relative merits of the various browsers and their idiosyncrasies, in the hopes that the OP will abandon any thoughts of using this Homepage script.:) :)

Twey
02-14-2006, 12:47 PM
Look at that Opera... what an IE clone :p

smoketer
02-15-2006, 12:19 AM
Yeah yeah... I know how much everyone hates IE and loves firefox and mozilla and the rest. For my purposes however, IE does just fine, and since most of my viewers use IE, then so much the better:-)

The script doesn't seem to work as is. Is there any tweeking that I need to do - any instructions - install to the body or the head?

BTW... here is the site http://thebyrdfamily.home.comcast.net

Twey
02-15-2006, 12:59 AM
Yeah yeah... I know how much everyone hates IE and loves firefox and mozilla and the rest.Not really; just the "hates IE" part :p Anyway, that was just a spinoff of our main point: that this capability really shouldn't exist in any browser, and certainly shouldn't be used.

Unfortunately, I currently lack qemu to test it (just installed Gentoo :)), so you'll have to wait for John to get back to this thread, I fear.

/EDIT: Ooh, 2000th post. And I spent it telling the OP to wait for John. Ah well :p

jscheuer1
02-15-2006, 05:06 AM
Nevertheless, congratulations are in order, Mad Professor II. At least now you will also have the dubious distinction of having folks who don't quite understand what you are trying to do to help them, the option of thinking you quite insane.

Thanks for all your help in these forums, Twey!

Now for my prepared response . . . (re: the browsers rants)

On second thought, I might say something I'll later regret because the truth is anyone that can code a browser, well my hat's off to 'em. Without them I'd be out of business. But, why waste a perfectly good chance to rant? You go on ahead, I may catch up later.

To smoketer,

I will have a look at your page and get back to you. Please forgive Twey and I his much deserved moment in the sun.

Twey
02-15-2006, 11:03 AM
At least now you will also have the dubious distinction of having folks who don't quite understand what you are trying to do to help them, the option of thinking you quite insane.I think a fair few of them already thought that :)
Thanks for all your help in these forums, Twey!They say you know you're a geek when you get paid to do what you'd do for pizza - and I've never had a single web-design job in my life. ;)

On second thought, I might say something I'll later regret because the truth is anyone that can code a browser, well my hat's off to 'em.Anyone can code a browser with sufficient (monetary) motivation. It's the ones who do it for free I admire :)

jscheuer1
02-16-2006, 02:44 PM
is there anyway to do the following?

1 - load the "set homepage to:______" script automatically
2 - remember what the user selected and next time NOT load the script

http://www.dynamicdrive.com/dynamicindex9/addhome.htm

eg:. John Doe comes to the site, is immediately prompted to set the homepage, and selects either "YES" or "NO". John Doe will never get prompted again.

Well, back to the matter at hand. This cannot be done precisely. The pop up dialogue for setting the home page must be initiated by a user clicking on something specifically for that purpose. This is according to the MS knowledge base. So, this is what I decided to do. I created a division that has the preliminary choice as to 'do you want to make this your homepage' It has a 'Yes' and an 'I'll Pass' button on it. If the user clicks yes, they still have to click yes again. Regardless of what they choose, a cookie is set so they won't ever see the choice again, unless they delete cookies. Additionally, if they choose yes, this will also prevent them from seeing the choice ever again unless they change their homepage. There are a few configuration items and the style of the division is in a style sheet, so that can be tweaked to one's content. None of this will show up if the browser isn't IE5+ compliant and whatever they choose, when they are finished with that, the division disappears:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
/* Begin style for set HomePage division */
#tmpDiv {
border:2px outset black;
font-family:verdana, arial, 'sans serif';
font-size:12px;
text-align:center;
width:300px;
height:50px;
position:absolute;
left:100px;
top:100px;
}
#tmpDiv input {
margin-top:5px;
height:90%;
}
/* End style for set HomePage division */
</style>
</head>
<body>
<!--[if gte IE 5]>
<span id=hp style="behavior:url(#default#homepage)"></span>
<script type="text/javascript">

/* Set HomePage script John Davenport Scheuer
* As first seen in dynamicdrive.com/forums
* User Name: jscheuer1
* This credit must remain for legal use */

var URLmark='http://mediajazzbynight.com/' // HomePage address
var URLtitle='mediajazzbynight.com' // Descriptive name of HomePage
var persist=365 // Set to number of days persistence for cookie

/////////////////////// No Need to Edit Below //////////////////

function createCookie(name,value,days)
{
if (days)
{
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++)
{
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}

function eraseCookie(name)
{
createCookie(name,"",-1);
}
var isFirst=readCookie('homePage')
if (!hp.isHomePage(URLmark)&&isFirst!=='beenthere')
document.write("<div id=\"tmpDiv\">Make "+URLtitle+" Your Homepage!<br><input type=\"button\" value=\"Yes!\" onClick=\"this.style.behavior='url(#default#homepage)';this.setHomePage(URLmark);createCookie('homePage','beenthere',persist);this.parentNode.style.display='none';\">&nbsp;<input type=\"button\" value=\"I'll Pass\" onClick=\"createCookie('homePage','beenthere',365);this.parentNode.style.display='none';\"></div>");
</script>
<![endif]-->
</body>
</html>

Notes: The test for the current home page setting will only be valid if the user is on the same domain as the homepage being tested for. Cookies are odd beasts. If you are having trouble with the cookies or make any changes to the cookie stuff, make sure to delete all cookies in your browser's tools/internet options section before complaining or testing the results of changes.

smoketer
02-16-2006, 11:15 PM
Great... I can figure out how to change somethings in here (look and feel). Is there anyway to do something like this?

RUN YOUR SCRIPT ON A BLANK PAGE (index.htm)

AFTER SCRIPT IS COMPLETE FORWARD TO ANOTHER PAGE
window.location="the new frameset page"

I have tried putting this in after the script, but it just redirects before user input.

jscheuer1
02-17-2006, 08:36 AM
One of the advantages of this script is that it can be integrated into any page and once the cookie is set, will no longer be a factor on that page and if the browser is not compliant, will never be a factor on that page. So, it could as easily go on one of the pages that initially displays via your frameset which, of course, should be index.htm (the frameset page that is) if you have a frameset site. What I have just stated would be the preferred method.

In addition, to have it switch to another page after completion and to go there everytime, once the cookie is set, you could add this bit:


<script type="text/javascript">

var nextPage='../blank.htm' // Set to the next page's address

function pollTemp(nextP){
if (document.getElementById)
if (document.getElementById('tmpDiv')){
if (document.getElementById('tmpDiv').style.display=='none')
window.location.replace(nextP)
}
else
window.location.replace(nextP)
}
if (document.getElementById)
setInterval("pollTemp(nextPage)", 500)
else
document.write('<p align="center"><a href="'+nextPage+'">Click Here to enter Site</a></p>')
</script>
<noscript> <!-- Set below href to next page's address as well -->
<p align="center"><a href="../blank.htm">Click Here to enter Site</a></p>
</noscript>

after the:


<![endif]-->

smoketer
02-19-2006, 11:35 PM
Ok.... there must be someting screwy going on with the initial script, OR the way I am implementing it.

If I put the script in the index.htm page it never loads the frameset and just stays blank. If I use the two scripts (homepage and redirect) individually as a new index and redirect, it automatically loads the new page without doing the homepage bit

Here is what I have at http://thebyrdfamily.home.comcast.net/redirect.htm


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
/* Begin style for set HomePage division */
#tmpDiv {
border:2px outset black;
font-family:verdana, arial, 'sans serif';
font-size:12px;
text-align:center;
width:300px;
height:50px;
position:absolute;
left:100px;
top:100px;
}
#tmpDiv input {
margin-top:5px;
height:90%;
}
/* End style for set HomePage division */
</style>
</head>
<body>
<!--[if gte IE 5]>
<span id=hp style="behavior:url(#default#homepage)"></span>
<script type="text/javascript">

/* Set HomePage script John Davenport Scheuer
* As first seen in dynamicdrive.com/forums
* User Name: jscheuer1
* This credit must remain for legal use */

var URLmark='http://thebyrdfamily.home.comcast.net/' // HomePage address
var URLtitle='THE BYRD'S NEST' // Descriptive name of HomePage
var persist=365 // Set to number of days persistence for cookie

/////////////////////// No Need to Edit Below //////////////////

function createCookie(name,value,days)
{
if (days)
{
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++)
{
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}

function eraseCookie(name)
{
createCookie(name,"",-1);
}
var isFirst=readCookie('homePage')
if (!hp.isHomePage(URLmark)&&isFirst!=='beenthere')
document.write("<div id=\"tmpDiv\">Make "+URLtitle+" Your Homepage!<br><input type=\"button\" value=\"Yes!\" onClick=\"this.style.behavior='url(#default#homepage)';this.setHomePage(URLmark);createCookie('homePage','beenthere',persist);this.parentNode.style.display='none';\">&nbsp;<input type=\"button\" value=\"I'll Pass\" onClick=\"createCookie('homePage','beenthere',365);this.parentNode.style.display='none';\"></div>");
</script>
<![endif]-->


<script type="text/javascript">

var nextPage="http://thebyrdfamily.home.comcast.net/byrd/index.htm" // Set to the next page's address

function pollTemp(nextP){
if (document.getElementById)
if (document.getElementById('tmpDiv')){
if (document.getElementById('tmpDiv').style.display=='none')
window.location.replace(nextP)
}
else
window.location.replace(nextP)
}
if (document.getElementById)
setInterval("pollTemp(nextPage)", 500)
else
document.write('<p align="center"><a href="'+nextPage+'">Click Here to enter Site</a></p>')
</script>
<noscript> <!-- Set below href to next page's address as well -->
<p align="center"><a href="http://thebyrdfamily.home.comcast.net/byrd/index.htm">Click Here to enter Site</a></p>
</noscript>


</body>
</html>

Let me know if I am missing something.

jscheuer1
02-20-2006, 05:42 AM
Yep! You're missing something alright but, not being familiar with how delimited strings work in javascript, you can hardly be blamed. I copied your page from your post and after taking care of this:


var URLtitle='THE BYRD\'S NEST' // Descriptive name of HomePage

It worked OK locally here. You see, if you have an apostrophe inside a string that is set off (delimited) by apostrophes, it needs to be escaped. Otherwise, it will break the script.