gpt4 book ai didi

Javascript - 如何在使用 Google App Engine 时加载 javascript 库?

转载 作者:行者123 更新时间:2023-11-30 12:45:51 25 4
gpt4 key购买 nike

我正在使用 Python、yaml 运行 Google App 引擎。现在我需要将 whichbrowser.net 与它一起使用(whichbrowser 也在使用 PHP,并且发生的错误在

但是当我尝试加载 http://whichbrowser.net/ 的 Javascript 库时它失败了“Uncaught SyntaxError: Unexpected token <” on detect.js line 1:

检测.js:

<?php

header("Content-Type: text/javascript");
header("Cache-Control: no-cache, no-store, must-revalidate, max-age=0");
header("Pragma: no-cache");
header("Expires: 0");

include('libraries/whichbrowser.php');

$options = array('headers' => apache_request_headers());
if (isset($_REQUEST['ua'])) $options['useragent'] = $_REQUEST['ua'];
if (isset($_REQUEST['e'])) $options['engine'] = intval($_REQUEST['e']);
if (isset($_REQUEST['f'])) $options['features'] = intval($_REQUEST['f']);
if (isset($_REQUEST['w'])) $options['width'] = intval($_REQUEST['w']);
if (isset($_REQUEST['h'])) $options['height'] = intval($_REQUEST['h']);
$detected = new WhichBrowser($options);

?>

index.html:

  (function(){var p=[],w=window,d=document,e=f=0;p.push('ua='+encodeURIComponent(navigator.userAgent));e|=w.ActiveXObject?1:0;e|=w.opera?2:0;e|=w.chrome?4:0;
e|='getBoxObjectFor' in d || 'mozInnerScreenX' in w?8:0;e|=('WebKitCSSMatrix' in w||'WebKitPoint' in w||'webkitStorageInfo' in w||'webkitURL' in w)?16:0;
e|=(e&16&&({}.toString).toString().indexOf("\n")===-1)?32:0;p.push('e='+e);f|='sandbox' in d.createElement('iframe')?1:0;f|='WebSocket' in w?2:0;
f|=w.Worker?4:0;f|=w.applicationCache?8:0;f|=w.history && history.pushState?16:0;f|=d.documentElement.webkitRequestFullScreen?32:0;f|='FileReader' in w?64:0;
p.push('f='+f);p.push('r='+Math.random().toString(36).substring(7));p.push('w='+screen.width);p.push('h='+screen.height);var s=d.createElement('script');
s.src='/whichbrowser/detect.js?' + p.join('&');d.getElementsByTagName('head')[0].appendChild(s);})();

应用程序.yaml:

- url: /whichbrowser
static_dir: whichbrowser

最佳答案

App Engine 上加载 JavaScript 的方式没有什么特别之处。它的加载方式与在任何其他平台/服务器上的加载方式相同。

关于Javascript - 如何在使用 Google App Engine 时加载 javascript 库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22511247/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com