简体   繁体   English

如何在Windows Phone 8应用程序中加载javascript文件?

[英]How to load javascript files in Windows phone 8 application?

In my Windows Phone 8 application, i am using WebBrowser control in a page. 在Windows Phone 8应用程序中,我在页面中使用WebBrowser控件。 When user clicks on a button, i am navigate a .html file onto the webBrowser. 当用户单击按钮时,我将.html文件导航到webBrowser。 The html is calling some css and js files in head section.Css files are loading perfectly but js files are not working. html在头部分调用了一些css和js文件.css文件正在完美加载,但js文件不起作用。 Can anyone please help me by giving their views on how js files will work? 任何人都可以通过提供有关js文件如何工作的意见来帮助我吗?

My XAML code: 我的XAML代码:

<phone:WebBrowser x:Name="Games_WebBrowser" Margin="0,0,0,0" />

Code behind: 后面的代码:

private void LeftNavCategories_Tap(object sender, System.Windows.Input.GestureEventArgs e)
    {
       Games_WebBrowser.Navigate(new Uri("/index.html", UriKind.Relative));
    }

Head section of .html file .html文件的头部

<head>
  <meta charset="utf-8">
  <link href="style/main.css" rel="stylesheet" type="text/css">
  <script src="js/bind_polyfill.js"></script>
  <script src="js/classlist_polyfill.js"></script>
  <script src="js/animframe_polyfill.js"></script>
  <script src="js/keyboard_input_manager.js"></script>
  <script src="js/html_actuator.js"></script>
  <script src="js/grid.js"></script>
  <script src="js/tile.js"></script>
  <script src="js/local_storage_manager.js"></script>
  <script src="js/game_manager.js"></script>
  <script src="js/application.js"></script>
</head>

I am not a windows phone developer, but I have done several Windows 8 apps and I have had issues with them too. 我不是Windows Phone开发人员,但是我已经完成了多个Windows 8应用程序,并且我也遇到了问题。 Most often this are problems with the same origin policy. 通常,这是同一原产地政策的问题。 This is what helped me mostly: 这是对我最大的帮助:

  1. Try to add a slash before the src <script src="/js/game_manager.js"></script> 尝试在src <script src="/js/game_manager.js"></script>前添加斜杠
  2. Try to add a file:// 尝试添加file://
  3. Add a ms-appx:// ( details ) 添加一个ms-appx://详细信息
  4. Some function-calls are marked as insecure . 一些函数调用被标记为insecure For example innerHtml() . 例如innerHtml() Try out if this could be an Issue by adding a alert("test") to your first js-file. 通过向您的第一个js文件添加alert("test")alert("test")是否可能是一个问题。 If this output is show, you don't have a problem with loading the files. 如果显示此输出,则说明加载文件没有问题。 Instead there are problems with the code itself. 相反,代码本身存在问题。 Try to test innerHtml than. 尝试测试innerHtml比。

If all this does not help, try to make a Javascript Project instead of a XAML Project 如果所有这些都无济于事,请尝试制作一个Javascript项目而不是XAML项目。

Here is the answer i found to my question. 这是我对我的问题的答案。

<phone:WebBrowser x:Name="Games_WebBrowser" IsScriptEnabled="True" Margin="0,0,0,0" />

I Got my answer by adding a simple tag IsScriptEnabled="True" by default it is false we need to make it true. 我通过添加默认情况下的简单标签IsScriptEnabled =“ True”来得到答案,这是错误的,我们需要将其设置为true。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM