我有一个相当大的音乐网站,有一个大型的艺术家数据库.我一直在注意其他音乐网站抓取我们网站的数据(我在这里和那里输入虚拟艺术家名称然后谷歌搜索它们).
如何防止屏幕抓取?它甚至可能吗?
鉴于此HTML:
<div>foo</div><div>bar</div><div>baz</div>
Run Code Online (Sandbox Code Playgroud)
你如何使它们像这样内联显示:
foo bar baz
不是这样的:
foo
bar
baz
当我想检测IE时,我使用此代码:
function getInternetExplorerVersion()
{
var rv = -1;
if (navigator.appName == 'Microsoft Internet Explorer')
{
var ua = navigator.userAgent;
var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
if (re.exec(ua) != null)
rv = parseFloat( RegExp.$1 );
}
return rv;
}
function checkVersion()
{
var msg = "You're not using Internet Explorer.";
var ver = getInternetExplorerVersion();
if ( ver > -1 )
{
msg = "You are using IE " + ver;
}
alert( msg );
}
Run Code Online (Sandbox Code Playgroud)
但IE11正在返回"你没有使用Internet Explorer".我该如何检测它?
debugging internet-explorer browser-detection forward-compatibility internet-explorer-11
我怎样才能为IE 11破解或编写CSS?我有一个在IE 11中看起来很糟糕的网站.我只是在这里搜索,但还没有找到任何解决方案.
有没有css选择器?
如何通过XSLT 将文件的doctype 干净地设置为HTML5 <!DOCTYPE html>
(在本例中为collective.xdv)
以下是我最好的谷歌foo能够找到的:
<xsl:output
method="html"
doctype-public="XSLT-compat"
omit-xml-declaration="yes"
encoding="UTF-8"
indent="yes" />
Run Code Online (Sandbox Code Playgroud)
生产:
<!DOCTYPE html PUBLIC "XSLT-compat" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Run Code Online (Sandbox Code Playgroud) 反正有没有检测JavaScript对象是否是正则表达式?
例如,我想做这样的事情:
var t = /^foo(bar)?$/i;
alert(typeof t); //I want this to return "regexp"
Run Code Online (Sandbox Code Playgroud)
这可能吗?
谢谢!
编辑:谢谢你的所有答案.看来我有两个非常好的选择:
obj.constructor.name === "RegExp"
Run Code Online (Sandbox Code Playgroud)
要么
obj instanceof RegExp
Run Code Online (Sandbox Code Playgroud)
这两种方法的主要优点/缺点是什么?
再次感谢!
我有一个名为的角度服务requestNotificationChannel
:
app.factory("requestNotificationChannel", function($rootScope) {
var _DELETE_MESSAGE_ = "_DELETE_MESSAGE_";
function deleteMessage(id, index) {
$rootScope.$broadcast(_DELETE_MESSAGE_, { id: id, index: index });
};
return {
deleteMessage: deleteMessage
};
});
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用jasmine对此服务进行单元测试:
"use strict";
describe("Request Notification Channel", function() {
var requestNotificationChannel, rootScope, scope;
beforeEach(function(_requestNotificationChannel_) {
module("messageAppModule");
inject(function($injector, _requestNotificationChannel_) {
rootScope = $injector.get("$rootScope");
scope = rootScope.$new();
requestNotificationChannel = _requestNotificationChannel_;
})
spyOn(rootScope, '$broadcast');
});
it("should broadcast delete message notification", function(done) {
requestNotificationChannel.deleteMessage(1, 4);
expect(rootScope.$broadcast).toHaveBeenCalledWith("_DELETE_MESSAGE_", { id: 1, index: 4 });
done();
});
});
Run Code Online (Sandbox Code Playgroud)
我读到了Jasmine中的异步支持,但由于我对使用javascript的单元测试不熟悉,因此无法使其正常工作.
我收到一个错误: …
"计算机科学只有两个难题:缓存失效和命名事物."
菲尔卡尔顿
是否存在使缓存无效的通用解决方案或方法; 要知道某个条目何时过时,所以您可以保证始终获得最新数据?
例如,考虑一个getData()
从文件中获取数据的函数.它根据文件的最后修改时间对其进行缓存,每次调用时都会检查该文件.
然后添加第二个函数transformData()
来转换数据,并在下次调用函数时缓存其结果.它不知道该文件 - 如何添加依赖关系,如果文件被更改,此缓存将变为无效?
您可以在getData()
每次调用时transformData()
调用它并将其与用于构建缓存的值进行比较,但这可能最终成本非常高.
我正在考虑在DOM中嵌入任意JSON,如下所示:
<script type="application/json" id="stuff">
{
"unicorns": "awesome",
"abc": [1, 2, 3]
}
</script>
Run Code Online (Sandbox Code Playgroud)
这类似于可以在DOM中存储任意HTML模板以供以后与JavaScript模板引擎一起使用的方式.在这种情况下,我们以后可以检索JSON并使用以下方法解析它:
var stuff = JSON.parse(document.getElementById('stuff').innerHTML);
Run Code Online (Sandbox Code Playgroud)
这有效,但这是最好的方法吗?这是否违反任何最佳做法或标准?
注意:我不是在寻找在DOM中存储JSON的替代方法,我已经确定这是我遇到的特定问题的最佳解决方案.我只是在寻找最好的方法.
css ×2
debugging ×2
html ×2
javascript ×2
algorithm ×1
angularjs ×1
architecture ×1
asynchronous ×1
caching ×1
constructor ×1
css-hack ×1
decoupling ×1
doctype ×1
dom ×1
embedding ×1
html5 ×1
instanceof ×1
jasmine ×1
json ×1
line ×1
python ×1
regex ×1
sys ×1
typeof ×1
unit-testing ×1
xdv ×1
xslt ×1