Skip to Main Content
建構Android應用程式--使用HTML、CSS和JavaScript 第二版
book

建構Android應用程式--使用HTML、CSS和JavaScript 第二版

by Jonathan Stark, Brian Jepson
May 2012
Intermediate to advanced content levelIntermediate to advanced
176 pages
3h 43m
Chinese
GoTop Information, Inc.
Content preview from 建構Android應用程式--使用HTML、CSS和JavaScript 第二版
進階樣式
49
if (url == undefined) {
$('#container').load('index.html #header ul', hijackLinks);
} else {
$('#container').load(url + ' #content', hijackLinks);
}
}
只攔截內部連結就好
如同多數網站,我們也有連結指向外部頁面(也就是其他網域的頁面)。我們不應該攔截
這些外部連結,因為把他們的
HTML
注入到我們專為
Android
準備的配置裡並沒有意義。
如範例
3-9
所示,我們可以加個條件句,檢查
URL
是否有我們的網域名稱存在。如果有,
就攔截該連結,而內容會載入當前頁面(
Ajax
在作用)。如果沒有,瀏覽器就正常導航
至該
URL
範例
3-9
:檢查
URL
網域名稱讓外部頁面正常載入
function hijackLinks() {
$('#container a').click(function(e){
var url = e.target.href;
if (url.match(window.location.hostname)) {
e.preventDefault();
loadPage(url);
}
});
var title = $('h2').html() || 'Hello!';
$('h1').html(title);
$('h2').remove();
$('#progress').remove();
}
url.ma ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

大模型应用开发极简入门 : 基于GPT-4和ChatGPT

大模型应用开发极简入门 : 基于GPT-4和ChatGPT

Olivier Caelen, Marie-Alice Blete
HBase管理指南

HBase管理指南

Posts & Telecom Press, Yifeng Jiang
自然语言处理与计算语言学

自然语言处理与计算语言学

Posts & Telecom Press, Bhargav Srinivasa-Desikan

Publisher Resources

ISBN: 9789862764817