DHTML Utopia Modern Web Design Using JavaScript & DOM- P12
Thông tin tài liệu:
Nội dung trích xuất từ tài liệu:
DHTML Utopia Modern Web Design Using JavaScript & DOM- P12 Chapter 8: Remote Scripting A simple iframe Below is an iframe, styled in size with CSS and displaying a different document. The HTML document displayed by the iframe is trivial and unstyled: File: simple-iframe-content.html This is a document in the iframe. Figure 8.1 shows the page display. Figure 8.1. The document with an iframe that displays another document. 200Licensed to siowchen@darke.biz Using There’s no sign that the iframe document is separate from that which surrounds it. Replacing iframes You can change the document that displays inside the iframe using a script loc- ated in the surrounding document. If the iframe is styled so as not to draw at- tention to itself, this technique creates the illusion that part of the parent docu- ment has changed. The iframe element’s src attribute is, like other attributes on HTML elements, available as a property of the corresponding DOM object. Here’s a simple script that can be called from a button press or link click; it merely changes the docu- ment displayed in the iframe: function changeIFrame() { document.getElementById(myframe).src = http://www.google.com/; } This example is so simple it doesn’t even need JavaScript. iframes act like normal frames and can therefore be the target of any hyperlink. You can display a link’s destination in an iframe by setting the target attribute on the link to the name of the iframe. Retrieving Data with iframes With further scripting, it’s possible for the iframe’s newly-loaded page to pass data back to its parent page. Scripts in the iframe content page can call functions in the parent page by referring to those parent-page functions as window.parent.functionName. This means that we can put any number of smart scripts in the parent page, ready for triggering by the iframe content as needed. Let’s look at a simple example. First, the main page: File: simple-iframe-2.html A simple iframe example 201Licensed to siowchen@darke.biz Chapter 8: Remote Scripting function receiveData(data) { document.getElementById(response).firstChild.nodeValue = data; } An iframe to which we send requests Send a request Response data received No data yet. There’s a lot going on in this document, so let’s pick through it slowly. First, there’s a link to a style sheet. It’s trivial stuff: File: simple-iframe-2.css div { border: 1px solid black; padding: 0 0 1em 0; width: 20em; } h2 { background-color: black; color: white; text-align: center; margin: 0; } div p { padding: 0 1em; } #scriptframe { width: 300px; height: 100px; 202Licensed to siowchen@darke.biz Using border: 2px solid red; } Second, there’s a JavaScript function, receiveData. Notice that it’s not called from anywhere in this page—it’s not even installed as an event listener. It’s just sitting there, waiting for someone else to use it. After that, there’s content. Fig- ure 8.2 shows the page as it appears when it first loads. Figure 8.2. The page ready for data exchanges via iframe. Let’s look at the page’s content tags closely. First is the iframe. Notice that both its id ...
Tìm kiếm theo từ khóa liên quan:
thiết kế flash giáo trình css thiết kê web kỹ thuật cắt html đồ họa máy tính 3d giáo trình photoshopGợi ý tài liệu liên quan:
-
Báo cáo thực tập: Đề tài thiết kế Web
77 trang 568 2 0 -
Đề thi thực hành môn Thiết kế Web - Trường Cao đẳng nghề Vĩnh Phúc
3 trang 267 2 0 -
vray for sketchup vietnamese PHẦN 3
10 trang 213 0 0 -
182 trang 175 0 0
-
Giáo trình CorelDRAW dành cho người mới học
48 trang 141 0 0 -
Giáo trình CorelDraw 10 - Tham khảo toàn diện: Phần 2
528 trang 133 0 0 -
Bài giảng Đồ họa máy tính: Khử mặt khuất - Ngô Quốc Việt
28 trang 127 0 0 -
MỘT SỐ ĐIỂM CẦN CHÚ Ý KHI THIẾT KẾ WEB
5 trang 113 0 0 -
GIÁO TRÌNH LẬP TRÌNH WEB_PHẦN 2_BÀI 3
3 trang 103 0 0 -
Giáo trình Nhập môn thiết kế website
58 trang 83 0 0 -
Tài liệu giảng dạy Thiết kế giao diện Web - Trường CĐ Kinh tế - Kỹ thuật Vinatex TP. HCM
88 trang 72 0 0 -
Giáo trình môn học Lý thuyết thông tin
136 trang 71 0 0 -
81 trang 68 0 0
-
112 trang 64 0 0
-
Hướng dân sử dụng Navicat để Create , Backup , Restore Database
7 trang 63 0 0 -
Giáo trình môn Kỹ thuật vi điều khiển: Thiết kế web và vi điều khiển - Chương 2
39 trang 59 0 0 -
Giáo trình Photoshop (Nghề: Lập trình máy tính-CĐ) - CĐ Cơ Giới Ninh Bình
231 trang 53 1 0 -
Bài giảng Đồ họa máy tính: Chương 3 - ThS. Trần Thị Minh Hoàn
29 trang 53 0 0 -
Giáo trình photoshop - Chương 3: Cơ bản về chỉnh sửa ảnhPhotoshop CS
19 trang 48 0 0 -
Lecture Computer graphics - Lecture 32
35 trang 46 0 0