SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Evangelist webchalkboard's Avatar
    Join Date
    Jan 2005
    Location
    Bristol, UK
    Posts
    494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Detecting a users homepage

    Hi,

    Is there a way in javascript to detect the users current homepage? Then if its not my site give them the option to set it to my site?

    Thanks,
    Tom
    Websites for Sale - Sell websites in a purpose built marketplace
    Then do some Shopping

  2. #2
    Word Painter silver trophy Shyflower's Avatar
    Join Date
    Oct 2003
    Location
    Winona, MN USA
    Posts
    10,054
    Mentioned
    142 Post(s)
    Tagged
    2 Thread(s)
    I certainly hope not. What I set for my homepage is really none of your business. If you want to give users the option to set your page as their home page, simply put the option on your homepage as millions have done before you.
    Linda Jenkinson
    "Say what you mean. Mean what you say. But don't say it mean." ~Unknown

  3. #3
    SitePoint Evangelist webchalkboard's Avatar
    Join Date
    Jan 2005
    Location
    Bristol, UK
    Posts
    494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the reply, and I take your point, however just because its none of my business doesn't mean its not possible to find out... I think a lot of people are under the impression that the web is somehow anonymous... when to a large extent it really isn't!
    Websites for Sale - Sell websites in a purpose built marketplace
    Then do some Shopping

  4. #4
    SitePoint Wizard bronze trophy bluedreamer's Avatar
    Join Date
    Jul 2005
    Location
    Middle England
    Posts
    3,267
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    The friendliest thing to do is to add a "Bookmark this page" script

  5. #5
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there a way in javascript to detect the users current homepage?
    Answer: No.

  6. #6
    SitePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, with contentWindow.location.href, using a hidden iframe it should be possible, in browsers that support home() -- mainly just Mozilla derivatives -- to determine what the current home page is, if it is from the same domain as the requesting page.

    So mainly, 'no', but not entirely.

  7. #7
    SitePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It would appear that you don't work as an actuary. Given the market penetration of Mozilla derivatives the rate should be closer to 80, 90 maybe even 100 times in 1000.

  8. #8
    SitePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The original poster asked for a way to determine if his was the homepage on the browser in question. That's a boolean question that can be ascertained with close to 100% reliebility on Mozilla (and earlier Netscape) browsers.

    I do stand corrected, however; clearly it isn't the math, but the logic that is the source of your misapprehension.

  9. #9
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Returning this thread to something constructive, here's a sample that works in Mozilla and IE5+. Replace the sHomePage variable with the one you want to test for.

    Code:
    <html XMLNS:IE>
    <head>
    <style type="text/css">
    @media all {
       IE\:HOMEPAGE {behavior:url(#default#homepage)}
    }
    iframe {
    	height: 0;
    	width: 0;
    	border: 0;
    }
    </style>
    <script type="text/javascript">
    var sHomePage = "http://someserver/somepage/"; // homepage to test for
    var nTimeout = 1000; // how long to wait for the homepage to load (Mozilla/FF)
    
    function detectBrowser() {
    	if( document.layers ) return "NS4";
    	if( window.opera ) return "Opera";
    	if( document.getElementById ) {
    		if( document.all ) return "IE5";
    		else return "NS6";
    	} else {
    		if( document.all ) return "IE4";
    		else return "Other";
    	}
    }
    
    function doHome() {
    	var b = detectBrowser();
    	if( b == "NS6" ) {
    		try {
    			window.frames["homeframe"].home();
    			window.setTimeout(checkHome, nTimeout);
    		} catch(e) {
    			alert("Your homepage is NOT my homepage");
    		}
    	} else if( b == "IE5" ) {
    		if( document.getElementById("iehometest").isHomePage(sHomePage) ) {
    			alert("Your homepage is set to my homepage" );
    		} else {
    			alert("Your homepage is NOT my homepage");
    		}
    	}
    }	
    function checkHome() {
    	if(window.frames["homeframe"].location.href == sHomePage) {
    		alert("Your homepage is set to my homepage");
    	} else {
    		alert("Your homepage is NOT my homepage");
    	}
    
    }
    window.onload = doHome;
    </script>
    </head>	
    <body>
    <IE:HOMEPAGE id="iehometest"/>
    <iframe name="homeframe"></iframe>
    </body>	
    </html>

  10. #10
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well done. But how can you suggest that goading a creative person to action isn't contructive?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •