Skip to content

Commit 64ce312

Browse files
author
zhangxinxu
committed
FF in iframe
fix a bug that FF in iframe won't excute
2 parents 717e9e7 + 408600c commit 64ce312

File tree

4 files changed

+38
-7
lines changed

4 files changed

+38
-7
lines changed

docs/data-rel.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ <h2>data-rel</h2>
1818
<p>此时,Mobilebone会根据对应<code>page</code>页面的前后顺序确定其正向过场还是反向。</p>
1919
<h3>其他说明</h3>
2020
<ol>
21+
<li><code>data-rel="back"</code>在以前两种场景都是有返回效果的。
22+
<pre>&lt;a href="#pageBack" <span style="color:#cd0000;">data-rel="back"</span>>返回&lt;/a></pre>
23+
<pre>&lt;a href="javascript:" <span style="color:#cd0000;">data-rel="back"</span>>返回&lt;/a></pre>
24+
<p>那它们的差别在什么地方呢?</p>
25+
<p>前者返回具有明确的目的性,知道前往的页面,虽然是返回,但是,<code>history</code>依然会push一条访问记录;而没有<code>href</code>的返回,也就是后者只会返回上一次的页面,其作用跟下面代码一样:</p>
26+
<pre>&lt;a href="javascript:history.back();">返回&lt;/a></pre>
27+
<p>真正意义上的浏览器返回,<code>history</code>回退至上一个记录,而不是再塞一条。所以,大家需要根据不同的返回场景做不同的处理。</p>
28+
</li>
2129
<li>
2230
<code>data-rel</code>其实还支持一个值,<code>"external"</code>. 作用和<code>data-ajax="false"</code>一致,感觉有些鸡肋,正犹豫要不要删掉,故没有放在上面讲。
2331
</li>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no">
6+
<title>即将前往仿QQ webapp页面...</title>
7+
</head>
8+
9+
<body>
10+
<div id="pageHome" class="page">
11+
<p>此示例作者:<a href="https://github.com/iancj">iancj</a></p>
12+
<p>即将前往仿QQ webapp页面...或直接<a href="http://iancj.github.io/qq/">点击这里</a></p>
13+
</div>
14+
<script>
15+
setTimeout(function() {
16+
location.replace("http://iancj.github.io/qq/");
17+
}, 3000);
18+
</script>
19+
</body>
20+
</html>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mobilebone",
3-
"version": "1.1.6",
3+
"version": "1.1.7",
44
"description": "Bone main for mobile web APP with a sigle page mode.",
55
"main": "src/mobilebone.js",
66
"directories": {

src/mobilebone.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@
2727
var isSimple = /^.[^:#\[\.,]*$/
2828

2929
// Is it suppory history API
30-
var supportHistory = "pushState" in history &&
31-
"replaceState" in history &&
32-
// When running inside a FF iframe, calling replaceState causes an error
33-
!( window.navigator.userAgent.indexOf( "Firefox" ) >= 0 && window.top !== window ) &&
34-
( window.navigator.userAgent.search(/CriOS/) === -1 );
30+
var supportHistory = "pushState" in history && "replaceState" in history;
3531

3632
Mobilebone.support = supportHistory;
3733

@@ -44,7 +40,7 @@
4440
*
4541
* @type string
4642
**/
47-
Mobilebone.VERSION = '1.1.6';
43+
Mobilebone.VERSION = '1.1.7';
4844

4945
/**
5046
* Whether catch attribute of href from element with tag 'a'
@@ -100,6 +96,13 @@
10096
**/
10197
Mobilebone.pushStateEnabled = true;
10298

99+
if (// When running inside a FF iframe, calling replaceState causes an error. So set 'pushStateEnabled = false'
100+
(window.navigator.userAgent.indexOf( "Firefox" ) >= 0 && window.top !== window)
101+
) {
102+
Mobilebone.pushStateEnabled = false;
103+
}
104+
105+
103106
/**
104107
* Function for transition
105108
* In most cases, you are unnecessary to use this function , unlike Mobilebone.createPage

0 commit comments

Comments
 (0)