[英]JAVASCRIPT: dynamically load manifest.json
whilst programming for HTML I stumbled on manifest.json files, for native Chrome/Android applications, but I can not load the manifest, situated at: "/manifest.json"; 虽然为HTML编程我偶然发现manifest.json文件,对于原生Chrome / Android应用程序,但我无法加载清单,位于:“/ manifest.json”; I used this jQuery code to add the link to the head tag.
我用这个jQuery代码添加了head标签的链接 。
$('head').append('<link rel="manifest" href="/manifest.json">');
But it adds it to the head of the document, but it doesn't read the manifest; 但它将它添加到文档的头部 ,但它不会读取清单; it just says: "No manifest found".
它只是说:“没有找到清单”。
Can anyone help me with this??? 谁能帮我这个???
you have to run the jQuery command before DOM ready 你必须在DOM准备好之前运行jQuery命令
Like this 像这样
Type 1: 类型1:
$(window).load(function() {
$('head').append('<link rel="manifest" href="/manifest.json">');
})
Type 2: Use $.getJSON 类型2:使用$ .getJSON
$.getJSON( "ajax/test.json", function( data ) {
var items = [];
$.each( data, function( key, val ) {
items.push( "<li id='" + key + "'>" + val + "</li>" );
});
$( "<ul/>", {
"class": "my-new-list",
html: items.join( "" )
}).appendTo( "body" );
});
Script Loaded in jQuery :- 在jQuery中加载的脚本 : -
In this below example i didn't include bootstrap in html but i included in 在下面这个例子中,我没有在html中包含bootstrap,但我包括在内
$(window).load()
It works. $(window).load()
它有效。
$(window).load(function(){ $('head').append('<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">'); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <html> <head> </head> <body> <table class="table"> <thead> <tr> <th>Firstname</th> <th>Lastname</th> <th>Email</th> </tr> </thead> <tbody> <tr> <td>Mary</td> <td>Moe</td> <td>mary@example.com</td> </tr> <tr> <td>July</td> <td>Dooley</td> <td>july@example.com</td> </tr> </tbody> </table> </body> </html>
No Script 没有脚本
<html> <head> </head> <body> <table class="table"> <thead> <tr> <th>Firstname</th> <th>Lastname</th> <th>Email</th> </tr> </thead> <tbody> <tr> <td>Mary</td> <td>Moe</td> <td>mary@example.com</td> </tr> <tr> <td>July</td> <td>Dooley</td> <td>july@example.com</td> </tr> </tbody> </table> </body> </html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.