Note that there are some explanatory texts on larger screens.

plurals
  1. POBlock access to page using JavaScript / other method?
    primarykey
    data
    text
    <h2>Some Background</h2> <p>I have a tumblog. </p> <p>I also have an <em>insane</em> ex-girlfriend.</p> <p>Said individual has been accessing my posts obsessively and I find this to be rather unnerving given the nature of our relationship (or lack thereof). My goal is to prevent access to her, or anyone who could be her / her friends / family without having to change my established URL.</p> <h2>Plan of Attack</h2> <p>Since I do not host my blog on a 3rd party host, I have little access to tools that would aid in blocking her access. However, I do own hosting if there is a solution that requires it. I'm no expert and as far as I can tell JavaScript is the only way to, at very least, trick her into believing she cannot access my page. </p> <p>I've hacked together a script and would <strong><em>really</em></strong> appreciate some guidance. Using jQuery and the jQuery Cookie plug-in, I've come up with some code that demonstrates my goal. <strong><em>Let's get to it.</em></strong></p> <pre><code>var ips = "{text:Ips}"; // String generated by tumblr: IP addresses separated by a space var towns = "{text:Towns}"; // Same but with towns var iparray = ips.split(" "); var townarray = towns.split(" "); $.getJSON("http://www.geoplugin.net/json.gp?jsoncallback=?", function(data){ // JSON request that returns geolocation data for(i = 0; i &lt; townarray.length; i++){ if (data['geoplugin_city'] == townarray[i]) // Test to see if user is accessing from a blacklisted town { if ($.cookie('banned_ip_tumblr')) // Looks for evidence of tracking cookie, if found: we stop loading, hide any content that was rendered, and send the user back up to 3 pages. { window.stop(); $('#all').hide(); // Div that wraps all content in body history.go(-3); history.go(-2); history.go(-1); } else // Sets a cookie destined to be stale. Really stale. Then proceed with hiding posts { $.cookie('banned_ip_tumblr', 'true', { expires: 365, path: '/' }); $('#all').hide(); history.go(-3); history.go(-2); history.go(-1); window.stop(); } } } for(i = 0; i &lt; iparray.length; i++){ if (data['geoplugin_request'] == iparray[i]) // Same as above, IP style. { if ($.cookie('banned_ip_tumblr')) { window.stop(); $('#all').hide(); history.go(-3); history.go(-2); history.go(-1); } else { $.cookie('banned_ip_tumblr', 'true', { expires: 365, path: '/' }); window.stop(); $('#all').hide(); history.go(-3); history.go(-2); history.go(-1); } } } } ); if ($.cookie('banned_ip_tumblr')) // If the user has been caught but is now connecting from a new host, there is a chance this will catch them { window.stop(); $('#all').hide(); history.go(-3); history.go(-2); history.go(-1); } </code></pre> <h2>Known Points of Failure</h2> <ul> <li>If the user has JS disabled, or is using a plug-in to filter JS, this will fail.</li> <li>If user is on a mobile device (tested with an iPod touch), this will fail.</li> <li>If user is using Internet Explorer, this will fail.</li> <li>If user uses a web-proxy, this will fail. </li> </ul> <h2>Closing Thoughts</h2> <p>This is not my ideal method of blocking access based on IP / geolocation, however, it is the best I can do with my current knowledge. The situation I am in unnerves me, but I also see it as an opportunity to explore less-common approaches to blocking a user's access. I am excited to hear any solutions that might be possible without JS, as well as those that do.</p> <p><em><strong>Please point out my mistakes</em></strong> (as I'm sure there are many) as they manifest in my code and/or concepts. I would like to get in the habit of writing code somewhat competently. </p> <p>This is my first post at Stack, though I have used this community many a time while throwing together projects. Thank you for taking some time to read and consider my problem, I look forward to getting some input. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload