我们正在建立一个带有音频播放器的Drupal站点,您可以在浏览页面(如soundcloud)时继续播放。
We're building a Drupal site with an audio player which should keep playing while you browse the page (something like soundcloud).
目前我们正在加载点击< a> 的网站带有ajax,并将html注入页面,并使用history.js来操纵该位置。
Currently we're loading clicked <a>'s sites with ajax and inject the html into the page and use history.js to manipulate the location.
尽管如此,存在一个主要的缺点:
There is a major downside though:
由于新加载的页面可能具有不同的css和js,因此我们必须比较当前的脚本,样式和链接元素到ajax响应文本(丑陋正则表达式),并且只添加新的但不存在的元素。通过这样做,加载另一个页面不会删除/删除/撤消一次执行的脚本。这可能会成为一个性能问题(反正使用正则表达式)。
Since a newly loaded page may have different css and js on it, we have to compare the current script, style and link elements to the ajax response text (ugly regex) and only add the new, yet non-existing elements. By doing so, loading another page wont delete/remove/undo once executed scripts. This may become a performance issue (while regex against markup is anyways).
使用iframe可能会解决这个问题和其他问题:
Using an iframe may solve this and other problems:
当您首次点击网站上的链接时,页面内容将被加载页面的iframe替换。音频播放器是在原来的dom,我。即在iframe之外。点击iframe中的链接可以在历史记录api中被捕获并使用。
When you first click a link on the site, the page content is replaced by an iframe which just loads the page. The audio player is in the original dom, i. e. outside the iframe. Clicking links inside the iframe can be caught and used within the history api aswell.
所以,虽然我从来没有想过我会这样想:我认为使用iframe可能是这里更好的选择,不是吗?
So, although I've never thought I'd think so: I think using an iframe may be the better option here, isnt it?
PS:我的主要问题是我无法控制网站上的不同页面有不同的脚本,风格真的没有问题。如果网站上只有一个巨大的静态js和css,我没有问题。
PS: my main problem is that I cant control that different pages on the website have different scripts, the styles really are no problem. If there was just one huge static js and css website-wide, I didnt have a problem.
更新
除了在iOS中,iframe解决方案可以正常工作。 iframe是如同地狱般的。仍然,我想我们将使用iframe解决方案。
The iframe solution works fine, except in iOS. Iframes are buggy as hell. Still, I think we're going with the iframe solution.
推荐答案我会说...保持简单,愚蠢。 为了获取iframe解决方案,我知道它会杀死你的一部分灵魂,但它是解决问题的最简单的方法,代表着将来遇到问题的最小变化。
I would say... keep it simple, stupid. Go for the iframe solution, I know it kills a part of your soul, but it is the easiest solution to your problem and represents the lowest change of running into problems in the future.
KISS。
更多推荐
我应该使用iframe而不是ajax吗?
发布评论