调试 jQuery Mobile 注入的脚本
在 jQuery Mobile 中,我可以使用 data-role=page
将“移动页面”定义为 div
。
这些可以存储在其他 HTML 文件中,并临时注入到 HTML 主页面中。
在这样的 div
中,我可以放置一个 script
标记,该脚本也将被注入到我的主页中。
该脚本不会在我的 DOM 中显示为 script
标记,而是似乎是内联注入的,因此它不会以标准方式出现在调试器(例如 FireBug 的脚本面板)中。
有没有人找到调试这些脚本的正常方法(希望在 FF 或 Chrome 中)?
编辑:
只是为了澄清 - “其他”页面中的脚本标记不是内联脚本。它是:
<div data-role="page" id="some_id">
<script type="text/javascript" src="MyScript.js"></script>
...
</div>
尽管如此,它还是作为内联脚本注入到 DOM 中。
顺便说一句 - 如果我将脚本标签放在 HTML 的 HEAD 中,它根本不会加载。
编辑2:
更多说明:
我正在编写一个框架,“扩展模块”将插入到客户站点上,并决定加载哪个模块(即带有脚本的附加“页面”)运行时的决定。因此,我事先不知道我的主页要加载哪些脚本,并且必须将加载推迟到“模块加载”时间。
我的最终目标是允许“模块”开发人员调试他们的脚本。为此,我想要一个解决方案,其中参考脚本文件可以像任何其他脚本一样在 FireBug/ChromeDevTools 中使用。
从 AJAX 加载的 html 中删除脚本标签并内联评估它似乎是标准的 jquery(核心,而不是移动)行为,而不是将脚本标签留在那里并让浏览器正常加载它。
我并不完全理解这背后的动机,它确实妨碍了我的调试选项:-(
顺便说一句,我正在使用 jQuery 1.5.2(与 1.5.1 的行为相同)和 jQuery Mobile alpha 4(与 3 相同)
In jQuery Mobile, I can define "mobile pages" as div
s with data-role=page
.
These can be stored in other HTML files, and injected ad-hoc into the main HTML page.
In such a div
I can put a script
tag, and that script will also be injected into my main page.
The script does not appear as a script
tag in my DOM, but rather seems to be injected inline, and thus it does not appear in a standard way in a debugger e.g. FireBug's script panel.
Has anyone found a normal way to debug these scripts (Hopefully in FF or Chrome) ?
EDIT:
Just to clarify - The script tag in the "other" page is not an inline script. It is a:
<div data-role="page" id="some_id">
<script type="text/javascript" src="MyScript.js"></script>
...
</div>
Still, it is injected as an inline script to the DOM.
BTW - if I put the script tag in the HTML's HEAD it is not loaded at all.
EDIT 2:
More clarifications:
I'm writing a framework into which "extension modules" will be plugged on customer site and decision which module (i.e. additional "pages" with scripts) to load is a runtime decision. Therefore I have no prior knowledge in my main page which scripts to load, and must defer loading to "module load" time.
My end goal here is to allow "module" developers to debug their scripts. For this I would like a solution where the references script files are available in FireBug/ChromeDevTools like any other script.
It seems like it's standard jquery (core, not mobile) behavior to remove the script tag from a AJAX-loaded html and eval it inline, instead of leaving the script tag there and letting the browser load it normally.
I don't really fully understand the motives behind this, and it really hampers my debugging options :-(
BTW, I'm using jQuery 1.5.2 (same behavior with 1.5.1) and jQuery Mobile alpha 4 (same with 3)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该脚本会动态附加到文档中,因此通常对 firebug 不可见。
有一个附加组件可以处理动态加载脚本的调试。
Inline Code Finder for Firebug
但它的最后一个版本是在 2009 年。如果您修改支持的版本,您可能可以使用它。顺便提一句。我相信你不应该使用 jquery mobile 的该功能。它为具有大量内联脚本块等的大型项目提供基本支持。
您应该在每个子页面上包含脚本并使其以这种方式工作
,或者
在需要时使用
.getScript()
如果它们太大而无法一直包含。[编辑]
是的,如果您将脚本放在头部,它将不会被加载。我重复一遍:将脚本放在每个页面的头部并绑定右侧页面的
pageshow
而不是普通的document.ready
The script is appended to document on the fly and therefore it's not normally visible to firebug.
There was an add-on that handled debugging dynamically loaded scripts.
Inline Code Finder for Firebug
but it's last release was in 2009. You probably can use it if you modify the supported versions.BTW. I belive you should not use that feature of jquery mobile. It's there for a basic support of huge projects with lots of inline script blocks, etc.
You should include your scripts on every subpage and make it work that way
or
Dynamically load your scripts when needed with
.getScript()
if they're too big to include all the time.[edit]
Yes, if you put the script in the head it will not be loaded. I repeat: Put the script in the head of EVERY page and bind
pageshow
of the right page instead of a normaldocument.ready