您可以引用本地 javascript 文件,但您需要先将它们加载到独立存储中。
这就是您可以将它们加载到本地存储中的方式。
var fileResourceStreamInfo = Application.GetResourceStream(new Uri("scripts/Hyphenator.js", UriKind.Relative));
if (fileResourceStreamInfo != null)
{
using (BinaryReader br = new BinaryReader(fileResourceStreamInfo.Stream))
{
byte[] data = br.ReadBytes((int)fileResourceStreamInfo.Stream.Length);
string strBaseDir = "scripts";
if(!appStorage.DirectoryExists(strBaseDir))
{
//Debug.WriteLine("Creating Directory :: " + strBaseDir);
appStorage.CreateDirectory(strBaseDir);
}
// This will truncate/overwrite an existing file, or
using (IsolatedStorageFileStream outFile = appStorage.OpenFile(AppRoot + "scripts/Hyphenator.js", FileMode.Create))
{
Debug.WriteLine("Writing data for " + AppRoot + "scripts/Hyphenator.js" + " and length = " + data.Length);
using (var writer = new BinaryWriter(outFile))
{
writer.Write(data);
}
}
}
}
然后你可以像这样引用它们:
<script type="text/javascript" src="scripts/Hyphenator.js"></script>