- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我的问题是这个(与讨论的 here 不同:在移动广告中,我会得到印象跟踪器,可能是 2、3 或 4。由于网络带宽有限,我想同时触发所有可用的跟踪器,而不是以瀑布方式(请不要问我为什么)。
我们一直在使用这段代码:
<script type="text/javascript">
var imp_1 = document.createElement("img");
imp_1.src = "tracker url 1 here";
var imp_2 = document.createElement("img");
imp_2.src = "tracker url 2 here";
var imp_3 = document.createElement("img");
imp_3.src = "tracker url 3 here";
var imp_4 = document.createElement("img");
imp_4.src = "tracker url 4 here";
</script>
更新所有这些 1x1 印象跟踪器都将指向不同的服务器,因为它们来自不同的归因合作伙伴。
我的问题是:
是否总是需要添加上述创建调用以将 img
变量添加到 DOM?在所有情况下都这样做是一种好的做法吗?
document.body.appendChild()
总能解决问题吗?
如果我改为使用 new Image()
代替 document.createElement()
,这里的工作方式会有所不同吗?我正致力于为每个跟踪器设置一个 setTimeout()
,以同时触发它们,但是 new Image()
是否能够自行完成?
最佳答案
Is it always required to add the above creative img vars to the DOM? Is it a good practice do so in all scenarios?
您不必向 DOM 添加图像。但是,如果您希望它在页面中可见,那么它必须以某种方式位于 DOM 中,因为将它添加到 DOM 就是它的显示方式。图像可能未添加到 DOM 的一种常见情况是在预缓存图像时(导致浏览器下载图像,以便在以后需要时它已经在缓存中)。
Would document.body.appendChild() always do the trick?
document.body.appendChild(img)
会将图像添加到 <body>
的末尾DOM 的一部分。它会一直这样做。但是,通常这并不是您想要图像在 DOM 中的确切位置,因此可能需要一些其他代码来定位其他位置。
If I instead used new Image() in place of the document.createElement() would that work differently here? I was working on putting a setTimeout() against each of the trackers, to fire them simultaneously, but would new Image() would be able to do that by itself?
您可以使用 new Image()
或 document.createElement("img")
.两者都将创建一个相同的图像对象。我不清楚你对 setTimeout()
的引用是什么是关于。图像标签没有任何内置的计时功能。如果你想在未来的某个特定时间加载图像,你可能想要使用 setTimeout()
调用以在未来的特定时间安排该事件。
您无法控制浏览器是同时请求 N 个图像,还是现在获取其中一些图像,以及在前几张图像完成后获取其中一些图像。浏览器通常对每个来源都有连接限制,并且它们只会同时触发这么多连接到同一来源。当后续请求在达到限制后进入时,它们会排队,直到一些当前打开的请求完成。
关于javascript - document.createElement ('img' ) v/s new Image()?哪一个要附加到 DOM?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31781046/
我知道它们是匿名类型,但我不明白 Razor 语法。在一些文档中,我找到了这样的示例: @Html.Label("Hello", new { htmlAtributes = new { id = "h
关于:new Object(new Array()) 有一个相当基本的问题,我自己确实无法给出答案,我正在寻求建议: 在js中实例化对象时使用如下方法: var obj = new Object();
在eclipse中右击项目时,“新建文件夹”、“新建源文件夹”和“新建包”有什么区别?他们似乎都在做同样的事情,引用文献并没有说太多。 谢谢 最佳答案 新建文件夹 在项目中创建一个新文件夹。 新建源文
几天来我一直在测试 bolt-cms,我试图了解它是如何工作的。 我想知道新页面、新条目和新展示柜之间有什么区别。 我已阅读 this它并没有填补空白。 最佳答案 Pages、Entries 和 Sh
更新:感谢所有的回答。我发现的最干净的解决方案是这个: if ( k(Arrays.asList(new LinkedList<>())); 我有一个递归方法,可以从列表中生成所有“n 选 k”组合。
我现在想知道这些指令是如何分配内存的。 例如,如果我得到代码怎么办: x = new int[5]; y = new int[5]; 如果分配了这些,它在 RAM 中的实际情况如何?是为每个变量保留整
我希望将其写入output.txt而不清除它 - 只是附加到末尾。但是,当我使用以下两种方法时: public void addEmails(ArrayList emails){ for (i
我正在分配内存,稍后将用于构造具有放置 new 的对象。我应该使用 operator new(n),还是应该使用 new unsigned char[n]?为什么? 最佳答案 因素: new[] 必须
基本上,我的问题是以下代码是否有效。 void* mem = operator new(sizeof(T)); T* instance = new(mem) T; delete instance; 如
很抱歉,如果之前有人问过这个问题,但我想就以下两种用法之间的区别提供一个简明的答案。 VS 似乎将它们都接受为有效代码。 private static void doSomeWork() { /
请告诉我这段代码在做什么,它是否创建多维数组(我认为不是)? 代码片段.. var hanoi_peg = new Array( new Array( 5, 4, 3, 2, 1,
这个问题在这里已经有了答案: String intern() behaviour (4 个答案) When should we use intern method of String on Stri
许多人说您应该避免使用 new Object、new Array(),而是使用 {}。 [] 和真/假。 使用字面量构造来获取对象或数组的新实例而不是使用 new 有什么好处?我知道 Crockfor
我正在开发一个存在内存泄漏的开源库。该库是围绕 boost::asio 构建的数据流服务。服务器端使用堆内存管理系统,该系统提供内存以容纳有限数量的 samples,同时它们等待通过 tcp 连接被推
我从以下函数中得到内存泄漏: int ReadWrite(int socket, char *readfile) { FILE *rf = NULL; rf = fopen(readfile,
在考虑类似的事情时 auto x = new T; 标准是否强制要求内存必须来自operator new——类特定的还是全局的?也就是说,如果缺少特定于类的 operator new,则没有办法从除全
只是出于好奇:为什么 C++ 选择 a = new A 而不是 a = A.new 作为实例化对象的方式?后者不是更像是面向对象的吗? 最佳答案 Just out of curiosity: Why
考虑以下代码: typedef SomeType type_t[2]; SomeType * arr1 = new type_t; //new or new[] ??? type_t * arr2
这个问题在这里已经有了答案: Difference between 'new operator' and 'operator new'? (8 个答案) 关闭 8 年前。 面试题:"new"运算符和
我正在为一个应用程序设计界面,以在 TableLayout 中显示从数据库中提取的一些数据。现在,默认 View 是纵向的,它由一个下拉菜单和一个三列的表格组成。当用户切换到横向时,微调器及其选项可以
我是一名优秀的程序员,十分优秀!