我正在写一个主题,只想向博客的管理员显示内容,但我不知道如何检测管理员是否已登录。
我确实注意到在 HTML 的底部,就在结束 body 标记之前有这段代码:
<iframe src="http://assets.tumblr.com/iframe.html?10&src=http%3A%2F%2Fstaff.tumblr.com%2F&lang=en_US&name=staff" scrolling="no" width="330" height="25" frameborder="0" style="position:absolute; z-index:1337; top:0px; right:0px; border:0px; background-color:transparent; overflow:hidden;" id="tumblr_controls"></iframe>
<!--[if IE]>
<script type="text/javascript">document.getElementById('tumblr_controls').allowTransparency=true;</script>
<![endif]-->
<script type="text/javascript">_qoptions={qacct:"p-19UtqE8ngoZbM"};</script>
<script type="text/javascript" src="http://edge.quantserve.com/quant.js"></script>
<noscript><img src="http://pixel.quantserve.com/pixel/p-19UtqE8ngoZbM.gif" style="display:none; border-width:0px; height:1px; width:1px;" alt=""/></noscript>
iframe
中的 URL (http://assets.tumblr.com/iframe.html?10&src=http%3A%2F%2Fstaff.tumblr.com%2F&lang=en_US&name=staff)指向一个页面,该页面会自行检查用户是否已登录。我只是无法弄清楚它是如何工作的。
因为此检查需要嵌入到主题代码中,所以它必须使用 JavaScript。
谢谢,斯宾塞
最佳答案
我认为问题无法解决,因为必须在服务器上进行此检查,并且由于 Tumblr Theme 的限制无法进行检查。 引擎。
更新:返回 JS 版本
iframe列表:
- Tumblr iframe for non-logged user
- Tumblr iframe for logged users [owner]
- Tumblr iframe for logged users [non-owner]
来自这些 iframe 的不同代码块:
未登录用户的 Tumblr iframe:
<script type="text/javascript">
var logged_in = (document.cookie.indexOf('logged_in=1') != -1);
</script>
…
<div style="position:absolute; top:3px; right:3px; white-space:nowrap; height:20px;">
<span id="logged_out_controls" style="display:none;">
<a href="https://www.tumblr.com/register" target="_top" id="follow_link">
<img id="follow_image" alt="Follow" style="width:58px;"/>
</a>
<a href="https://www.tumblr.com/register/join_tumblr" target="_blank"
id="join_link">
<img id="join_image" alt="Join Tumblr" style="width:105px;"/>
</a>
</span>
</div>
登录用户的 Tumblr iframe [所有者]:
<div style="position:absolute; top:3px; right:3px; white-space:nowrap; height:20px;">
<a target="_top" href="http://www.tumblr.com/customize?redirect_to=http%3A%2F%2Fexample.com%2F">
<img src="http://assets.tumblr.com/images/iframe_customize_alpha.png?1016" alt="Customize" style="height:20px;width:80px; border-width:0px; display:block; float:left; cursor:pointer;" />
</a>
<a target="_top" href="http://www.tumblr.com/dashboard">
<img src="http://assets.tumblr.com/images/iframe_dashboard_alpha.png?1016" alt="Dashboard" style="height:20px; width:81px; border-width:0px; display:block; float:left; cursor:pointer;" />
</a>
</div>
登录用户的 Tumblr iframe [非所有者]:
<div style="position:absolute; top:3px; right:3px; white-space:nowrap; height:20px;">
<form action="/follow" method="post" style="display:block; float:left;"onsubmit="_gaq.push(['_trackEvent', 'Iframe', 'Follow', 'example-com');">
<input type="hidden" name="form_key" value="83jbGySgEVpQGOoZALqqoSaKfjs"/>
<input type="hidden" name="id" value="example-com"/>
<input type="image" src="http://assets.tumblr.com/images/iframe_follow_alpha.png?1016"style="width:58px; height:20px; border-width:0px; display:block;margin-left:3px; cursor:pointer;"alt="Follow"/>
</form>
<a target="_top" href="http://www.tumblr.com/dashboard">
<imgsrc="http://assets.tumblr.com/images/iframe_dashboard_alpha.png?1016" alt="Dashboard" style="height:20px; width:81px; border-width:0px; display:block; float:left; cursor:pointer;"/>
</a>
</div>
可检测的差异:
未记录 的 iframe 有奇怪的脚本行:
var logged_in = (document.cookie.indexOf('logged_in=1') != -1);
NO
href
属性包含“自定义”模式的链接(CSS 方式:a[href*='customize']
);href
属性的NO 链接包含“仪表板”模式(CSS 方式:a[href*='dashboard']
) ;
已登录用户[所有者]的iframe:
href
属性的链接包含“dashboard”模式(CSS 方式:a[href*='dashboard']
);href
属性的链接包含“自定义”模式(CSS 方式:a[href*='customize']
);没有NO 'follow' 形式;
已登录用户[非所有者]的iframe:
href
属性的链接包含“dashboard”模式(CSS 方式:a[href*='dashboard']
);有'follow'的形式;
NO
href
属性包含“自定义”模式的链接(CSS 方式:a[href*='customize']
);
结论
但是我发现这个解决方案非常脆弱,我认为它可以检测是基于上面列出的差异的当前博客的用户所有者。
关于javascript - 如何检测 tumblr 用户是否已登录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11626074/