如何實現動態創建iframe,以及拖動iframe

創建內嵌浮動框架。

成員表

下面的表格列出了 iframe 對象引出的成員。請單擊左側的標籤來選擇你想要查看的成員類型。

標籤屬性/屬性

顯示:
標籤屬性/屬性
行爲
集合
事件
濾鏡
方法
對象
樣式
標籤屬性 屬性 描述
ALIGN align 設置或獲取表格排列。
ALLOWTRANSPARENCY allowTransparency 設置或獲取對象是否可爲透明。
APPLICATION APPLICATION 表明對象的內容是否爲 HTML 應用程序(HTA),以便免除瀏覽器安全模式。
ATOMICSELECTION 指定元素及其內容是否可以一不可見單位統一選擇。
BEGIN begin 設置或獲取時間線在該元素上播放前的延遲時間。
BORDER border 設置或獲取框架間的空間,包括 3D 邊框。
canHaveChildren 獲取表明對象是否可以包含子對象的值。
canHaveHTML 獲取表明對象是否可以包含豐富的 HTML 標籤的值。
CLASS className 設置或獲取對象的類。
contentWindow 獲取指定的 frame 或 iframe 的 window 對象。
DATAFLD dataFld 設置或獲取由 dataSrc 屬性指定的綁定到指定對象的給定數據源的字段。
DATASRC dataSrc 設置或獲取用於數據綁定的數據源。
disabled 獲取表明用戶是否可與該對象交互的值。
END end 設置或獲取表明元素結束時間的值,或者元素設置爲重複的簡單持續終止時間。
firstChild 獲取對象的 childNodes 集合的第一個子對象的引用。
FRAMEBORDER frameBorder 設置或獲取是否顯示框架的邊框。
hasMedia 獲取一個表明元素是否爲 HTML+TIME 媒體元素的 Boolean 值。
HEIGHT height 設置或獲取對象的高度。
HIDEFOCUS hideFocus 設置或獲取表明對象是否顯式標明焦點的值。
HSPACE hspace 設置或獲取對象的水平邊距。
ID id 獲取標識對象的字符串。
innerText 設置或獲取位於對象起始和結束標籤內的文本。
isContentEditable 獲取表明用戶是否可編輯對象內容的值。
isDisabled 獲取表明用戶是否可與該對象交互的值。
isMultiLine 獲取表明對象的內容是包含一行還是多行的值。
isTextEdit 獲取是否可使用該對象創建一個 TextRange 對象。
LANG lang 設置或獲取要使用的語言。
LANGUAGE language 設置或獲取當前腳本編寫用的語言。
lastChild 獲取該對象 childNodes 集合中最後一個子對象的引用。
longDesc 設置或獲取對象長描述的統一資源標識符(URI)。
MARGINHEIGHT marginHeight 設置或獲取顯示框架中文本之前的上下邊距高度。
MARGINWIDTH marginWidth 設置或獲取顯示框架中文本之前的左右邊距寬度。
NAME name 設置或獲取框架的名稱。
nextSibling 獲取對此對象的下一個兄弟對象的引用。
nodeName 獲取特定結點類型的名稱。
nodeType 獲取所需結點的類型。
nodeValue 設置或獲取結點的值。
offsetHeight 獲取對象相對於版面或由父座標 offsetParent 屬性指定的父座標的高度。
offsetLeft 獲取對象相對於版面或由 offsetParent 屬性指定的父座標的計算左側位置。
offsetParent 獲取定義對象 offsetTop 和 offsetLeft 屬性的容器對象的引用。
offsetTop 獲取對象相對於版面或由 offsetTop 屬性指定的父座標的計算頂端位置。
offsetWidth 獲取對象相對於版面或由父座標 offsetParent 屬性指定的父座標的寬度。
onOffBehavior 獲取表明指定的  Microsoft? DirectAnimation? 行爲是否正在運行的對象。
outerHTML 設置或獲取對象及其內容的 HTML 形式。
outerText 設置或獲取對象的文本。
ownerDocument 設置或獲取結點關聯的 document 對象。
parentElement 獲取對象層次中的父對象。
parentNode 獲取文檔層次中的父對象。
parentTextEdit 獲取文檔層次中可用於創建包含原始對象的 TextRange 的容器對象。
previousSibling 獲取對此對象的上一個兄弟對象的引用。
readyState 獲取對象的當前狀態。
readyState 獲取表明對象當前狀態的值。
recordNumber 獲取數據集中生成對象的原始記錄。
scopeName 獲取爲該元素定義的命名空間。
SCROLLING scrolling 設置或獲取框架是否可被滾動。
SECURITY SECURITY 獲取表明 frame 或 iframe 的源文件是否應用了特定的安全限制的值。
sourceIndex 獲取對象在源序中的依次位置,即對象出現在 document 的 all 集合中的順序。
SRC src 設置或獲取要由對象裝入的 URL。
STYLE 爲該設置元素設置內嵌樣式。
SYNCMASTER syncMaster 設置或獲取時間容器是否必須在此元素上同步回放。
SYSTEMBITRATE 獲取系統中大約可用帶寬的 bps。
SYSTEMCAPTION 表明是否要顯示文本來代替演示的的音頻部分。
SYSTEMLANGUAGE 表明是否在用戶計算機上的選項設置中選中了給定語言。
SYSTEMOVERDUBORSUBTITLE 指定針對那些正在觀看演示但對被播放的音頻所使用的語言並不熟悉的用戶來說是否要渲染配音或字幕。
TABINDEX tabIndex 設置或獲取定義對象的 Tab 順序的索引。
tagName 獲取對象的標籤名稱。
tagUrn 設置或獲取在命名空間聲明中指定的統一資源名稱(URN)。
TIMECONTAINER timeContainer 設置或獲取與元素關聯的時間線類型。
TITLE title 設置或獲取對象的諮詢信息(工具提示)。
uniqueID 獲取爲對象自動生成的唯一標識符。
UNSELECTABLE 指定該元素不可被選中。
VSPACE vspace 設置或獲取對象的垂直邊距。
WIDTH width 設置或獲取對象的寬度。


標籤屬性/屬性

行爲

行爲 描述
clientCaps 提供關於 Internet Explorer 支持的特性的信息,以及提供即用即裝的方法。
download 下載文件並在下載完成後通知一個指定的回調函數。
homePage 包含關於用戶主頁的信息。
time 爲 HTML 元素提供一個活動的時間線。
time2 爲 HTML 元素或一組元素提供一個活動的時間線。

集合

集合 描述
all 返回對象所包含的元素集合的引用。
attributes 獲取對象標籤屬性的集合。
behaviorUrns 返回標識附加到該元素行爲的統一資源名稱(URN)字符串的集合。
childNodes 獲取作爲指定對象直接後代的 HTML 元素和 TextNode 對象的集合。
children 獲取作爲對象直接後代的 DHTML 對象的集合。

事件

事件 描述
onactivate 當對象設置爲活動元素時觸發。
onafterupdate 當成功更新數據源對象中的關聯對象後在數據綁定對象上觸發。
onbeforedeactivate 在 activeElement 從當前對象變爲父文檔其它對象之前立即觸發。
onbeforeupdate 當成功更新數據源對象中的關聯對象前在數據綁定對象上觸發。
onblur 在對象失去輸入焦點時觸發。
oncontrolselect 當用戶將要對該對象製作一個控件選中區時觸發。
ondeactivate 當 activeElement 從當前對象變爲父文檔其它對象時觸發。
onerrorupdate 更新數據源對象中的關聯數據出錯時在數據綁定對象上觸發。
onfocus 當對象獲得焦點時觸發。
onload 在瀏覽器完成對象的裝載後立即觸發。
onmove 當對象移動時觸發。
onmoveend 當對象停止移動時觸發。
onmovestart 當對象開始移動時觸發。
onreadystatechange 當對象狀態變更時觸發。
onresizeend 當用戶更改完控件選中區中對象的尺寸時觸發。
onresizestart 當用戶開始更改控件選中區中對象的尺寸時觸發。
ontimeerror 當特定時間錯誤發生時無條件觸發,通常由將屬性設置爲無效值導致。

濾鏡

濾鏡屬性 描述
Alpha 調整對象內容的不透明度。
AlphaImageLoader 在對象的邊界和對象背景到內容之間顯示圖像,可選剪裁或縮放圖像大小。當裝入便攜網絡圖像(PNG)時,從 0 到 100% 的 透明度都是支持的。
Barn 以開門或關門的運動方式顯示對象的新內容。
BasicImage 調整對象內容的顏色處理、圖像旋轉或不透明度。
BlendTrans 以漸隱原始內容的形式顯示對象的新內容。
Blinds 以打開或關閉盲點的運動方式顯示對象的新內容。
Blur 模糊對象的內容以便使其看起來失去焦點。
CheckerBoard 以揭開覆蓋在原始內容上的棋盤的形式顯示對象的新內容。
Chroma 將對象內容的指定顏色顯示爲透明。
Compositor 以新舊內容邏輯顏色組合的形式顯示對象的新內容。每個版本的顏色和 alpha 值都會被計算用來決定輸出圖像的最終顏色。
DropShadow 創建對象內容的實體陰影,偏移量位於指定方向。這將使得內容看起來是浮動的因此會產生陰影。
Emboss 使用灰度值對對象以浮雕紋理顯示。
Engrave 使用灰度值對對象以雕刻紋理顯示。
Fade 以漸隱原始內容的形式顯示對象的新內容。
FlipH 以沿水平方向翻轉的形式顯示對象內容。
FlipV 以沿垂直方向翻轉的形式顯示對象內容。
Glow 在對象邊緣外側添加光暈以便使其看起來像發光的樣子。
Gradient 在對象的背景和內容之間顯示一個漸變色彩的表面。
GradientWipe 以在原有內容上覆蓋漸變帶的形式顯示對象的新內容。
Gray 以灰度顯示對象內容。
ICMFilter 根據圖像顏色管理(ICM)配置文件轉換對象的彩色內容。這將允許指定內容的顯示效果得以改善,或者在打印機或監視器等硬件設備上模擬顯示。
Inset 以對角線方向顯示對象的新內容。
Invert 反轉對象內容的色調、飽和度和亮度。
Iris 以彩虹效果顯示對象的新內容,這與照相機光圈打開相似。
Light 在對象的內容上創建燈光效果。
MaskFilter 將對象內容的透明像素顯示爲彩色遮罩,將非透明像素顯示爲透明。
Matrix 使用矩陣變換縮放、旋轉或顯現對象的內容。
MotionBlur 以運動模糊的效果顯示對象內容。
Pixelate 將對象的內容顯示爲彩色方塊,其顏色取決於該方塊所替代區域的平均顏色值。此濾鏡顯示可用於切換。
RadialWipe 以輻射狀擦除的形式顯現對象的新內容。
RandomBars 以隨機像素線爆炸的形式顯現對象的新內容。
RandomDissolve 以隨機像素爆炸的形式顯現對象的新內容。
Redirect 目前還不支持。
RevealTrans 使用 24 種預先定義的切換效果顯現對象的新內容。
Shadow 創建對象內容的實體陰影,偏移量位於指定方向。這將創建陰影效果。
Slide 以圖像滑行的形式顯現對象的新內容。
Spiral 以螺旋運動的形式顯現對象的新內容。
Stretch 以拉伸覆蓋原始內容的形式顯現對象的新內容。有一個選項類似立方體從一個表面轉到另外一個表面。
Strips 以條形覆蓋的形式顯現對象的原始內容,好像有一把鋸將原始內容鋸開。
Wave 在對象的內容上執行垂直方向的正弦波扭曲。
Wheel 以旋轉運動的形式顯現對象的新內容,好像輪子滾過原始內容。
Xray 更改對象內容的顏色深度將其以黑白顯示。
Zigzag 在對象上將對象的新內容進行來回移動以便覆蓋原始內容。

方法

方法 描述
addBehavior 給元素附加一個行爲。
appendChild 給對象追加一個子元素。
applyElement 使得元素成爲其它元素的子元素或父元素。
attachEvent 將指定函數綁定到事件,以便每當該事件在對象上觸發時都調用該函數。
blur 使元素失去焦點並觸發 onblur 事件。
clearAttributes 從對象中刪除全部標籤屬性和值。
cloneNode 從文檔層次中複製對對象的引用。
componentFromPoint 通過特定事件返回對象在指定座標下的位置。
contains 檢查對象中是否包含給定元素。
detachEvent 從事件中取消指定函數的綁定,這樣當事件觸發時函數就不會收到通知了。
dragDrop 初始化拖曳事件。
fireEvent 觸發對象的指定事件。
focus 使得元素得到焦點並執行由 onfocus 事件指定的代碼。
getAdjacentText 返回鄰接文本字符串。
getAttribute 獲取指定標籤屬性的值。
getAttributeNode 獲取由 attribute.name 屬性引用的 attribute 對象。
getElementsByTagName 獲取基於指定元素名稱的對象集合。
getExpression 獲取給定屬性的表達式。
hasChildNodes 返回表明對象是否有子對象的值。
insertAdjacentElement 在指定位置插入元素。
insertAdjacentHTML 在指定位置的元素中插入給定的 HTML 文本。
insertAdjacentText 在指定位置插入給定的文本。
insertBefore 在文檔層次中插入元素作爲父對象的子結點。
mergeAttributes 複製所有讀/寫標籤屬性到指定元素。
normalize 合併鄰接 TextNode 對象以便生成一個常規的文檔對象模型。
removeAttribute 刪除對象的給定標籤屬性。
removeAttributeNode 從對象中刪除刪除 attribute 對象。
removeBehavior 分離元素的行爲。
removeChild 從元素上刪除子結點。
removeExpression 從指定屬性中刪除表達式。
removeNode 從文檔層次中刪除對象。
replaceAdjacentText 替換元素的鄰接文本。
replaceChild 用新的子元素替換已有的子元素。
replaceNode 用其它元素替換對象。
scrollIntoView 將對象滾動到可見範圍內,將其排列到窗口頂部或底部。
setActive 設置對象爲當前對象而不將對象置爲焦點。
setAttribute 設置指定標籤屬性的值。
setAttributeNode 設置 attribute 對象爲對象的一部分。
setExpression 設置指定對象的表達式。
swapNode 交換文檔層次中兩個對象的位置。

對象

對象 描述
runtimeStyle 代表了居於全局樣式表、內嵌樣式和 HTML 標籤屬性指定的格式和樣式之上的對象的格式和樣式。
style 代表了給定元素所有可能的內嵌樣式的當前設置。

樣式

樣式標籤屬性 樣式屬性 描述
ACCELERATOR accelerator 設置或獲取表明對象是否包含快捷鍵的字符串。
background-attachment backgroundAttachment 設置或獲取背景圖像如何附加到文檔內的對象中。
background-color backgroundColor 設置或獲取對象內容後的顏色。
background-position-x backgroundPositionX 設置或獲取 backgroundPosition 屬性的 x 座標。
background-position-y backgroundPositionY 設置或獲取 backgroundPosition 屬性的 y 座標。
behavior behavior 設置或獲取 DHTML 行爲的位置。
border-bottom borderBottom 設置或獲取對象下邊框的屬性。
border-bottom-color borderBottomColor 設置或獲取對象下邊框的顏色。
border-bottom-style borderBottomStyle 設置或獲取對象下邊框的樣式。
border-bottom-width borderBottomWidth 設置或獲取對象下邊框的寬度。
border-color borderColor 設置或獲取對象的邊框顏色。
border-left borderLeft 設置或獲取對象左邊框的屬性。
border-left-color borderLeftColor 設置或獲取對象左邊框的顏色。
border-left-style borderLeftStyle 設置或獲取對象左邊框的樣式。
border-left-width borderLeftWidth 設置或獲取對象左邊框的寬度。
border-right borderRight 設置或獲取對象右邊框的屬性。
border-right-color borderRightColor 設置或獲取對象右邊框的顏色。
border-right-style borderRightStyle 設置或獲取對象右邊框的樣式。
border-right-width borderRightWidth 設置或獲取對象右邊框的寬度。
border-style borderStyle 設置或獲取對象上下左右邊框的樣式。
border-top borderTop 設置或獲取對象上邊框的屬性。
border-top-color borderTopColor 設置或獲取對象上邊框的顏色。
border-top-style borderTopStyle 設置或獲取對象上邊框的樣式。
border-top-width borderTopWidth 設置或獲取對象上邊框的寬度。
border-width borderWidth 設置或獲取對象上下左右邊框的寬度。
bottom bottom 設置或獲取對象相對於文檔層次中下個定位對象的底部的位置。
clear clear 設置或獲取對象是否允許在其左側、右側或兩邊放置浮動對象,以防下段文本顯示在浮動對象上。
clip clip 設置或獲取定位對象的哪個部分可見。
cursor cursor 設置或獲取當鼠標指針指向對象時所使用的鼠標指針。
display display 設置或獲取對象是否要渲染。
filter filter 設置或獲取應用於對象的濾鏡或濾鏡集合。
height height 設置或獲取對象的高度。
layout-grid layoutGrid 設置或獲取指定文本字符版面的組合文檔格線屬性。
layout-grid-mode layoutGridMode 設置或獲取文本佈局網格是否使用二維。
left left 設置或獲取對象相對於文檔層次中下個定位對象的左邊界的位置。
margin margin 設置或獲取對象的上下左右邊距。
margin-bottom marginBottom 設置或獲取對象的下邊距寬度。
margin-left marginLeft 設置或獲取對象的左邊距寬度。
margin-right marginRight 設置或獲取對象的右邊距寬度。
margin-top marginTop 設置或獲取對象的上邊距寬度。
overflow-x overflowX 設置或獲取當內容超出對象寬度時如何管理對象內容。
overflow-y overflowY 設置或獲取當內容超出對象高度時如何管理對象內容。
pixelBottom 設置或獲取對象的下方位置。
pixelHeight 設置或獲取對象的高度。
pixelLeft 設置或獲取對象的左側位置。
pixelRight 設置或獲取對象的右側位置。
pixelTop 設置或獲取對象的上方位置。
pixelWidth 設置或獲取對象的寬度。
posBottom 設置或獲取以 bottom 標籤屬性指定的單位的對象下方位置。
posHeight 設置或獲取以 height 標籤屬性指定的單位的對象高度。
position position 設置或獲取對象所使用的定位方式。
posLeft 設置或獲取以 left 標籤屬性指定的單位的對象左側位置。
posRight 設置或獲取以 right 標籤屬性指定的單位的對象右側位置。
posTop 設置或獲取以 top 標籤屬性指定的單位的對象上方位置。
posWidth 設置或獲取以 width 標籤屬性指定的單位的對象寬度。
right right 設置或獲取對象相對於文檔層次中下個已定位的對象的右邊界的位置。
float styleFloat 設置或獲取文本要繞排到對象的哪一側。
text-autospace textAutospace 設置或獲取自動留空和文本的窄空間寬度調整。
top top 設置或獲取對象相對於文檔層次中下個定位對象的上邊界的位置。
visibility visibility 設置或獲取對象的內容是否顯示。
z-index zIndex 設置或獲取定位對象的堆疊次序。
zoom zoom 設置或獲取對象的放大比例。

註釋

IFRAME 元素也就是文檔中的文檔,或者好像浮動的框架(FRAME)。frames 集合提供了對 IFRAME 內容的訪問。請使用 frames 集合讀寫 IFRAME 內包含的元素。例如,如果要訪問 iframe 內 body 對象的 backgroundColor 樣式,語法應爲:

sColor = document.frames("sFrameName").document.body.style.backgroundColor;

通過 iframe 對象所在頁面的對象模型,你可以訪問 iframe 對象的屬性,但不能訪問其內容。例如,訪問 iframe 對象的 border 樣式的語法應爲:

sBorderValue = document.all.oFrame.style.border;

注意 iframe 的屬性必須使用前綴 document.all 訪問,例如 document.all.iframeId.marginWidth。
Internet Explorer 5.5 支持浮動框架的內容透明。如果想要爲浮動框架定義透明內容,則必須滿足下列條件。

與 IFRAME 元素一起使用的 ALLOWTRANSPARENCY 標籤屬性必須設置爲 true。
在 IFRAME 內容源文檔,background-color 或 BODY 元素的 BGCOLOR 標籤屬性必須設置爲 transparent。
參看使用透明的浮動框架可以獲得關於透明浮動框架更多的信息。

此元素在  Microsoft? Internet Explorer 4.0 的 HTML 和腳本中可用。

此元素是一個塊元素。

此元素需要關閉標籤。

下面有兩示例,示例1是如何拖動iframe,示例2是在iframe中添加div,這樣能使得拖動iframe很流暢。

示例1

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Untitled Document </title>
<script>
function createIframe(){
var frm = document.createElement("iframe");
frm.id = 'ifrm';
frm.name = 'ifrm';
frm.style.position = 'absolute';
frm.style.width = "480px";
frm.style.height = "180px";
frm.style.left = document.body.scrollLeft + event.clientX + 50 + "px";
frm.style.top = document.body.scrollTop + event.clientY - 180 + "px";
frm.style.display = 'none';
frm.style.border = "solid #33ddff  5px;";//00CCFF
//frm.style.border = "solid #000 2px;";
frm.attachEvent("onload",addEvent);
function addEvent(){
var frm = event.srcElement;
var id = event.srcElement.id;
var frmCont = frm.contentWindow.document;
frmCont.drag = false;
frmCont.initX = 0;
frmCont.initY = 0;
frmCont.posX = 0;
frmCont.posY = 0;
if(frmCont.getElementById("drag") != null){
frmCont.getElementById("drag").frmid = id;
frmCont.getElementById("drag").onmousedown = function(){
var _event = this.document.parentWindow.event;
var doc = this.document;
var frm = parent.document.getElementById(this.frmid);
doc.posX = _event .x;
doc.posY = _event .y;
                doc.initX = parseInt(frm.style.left);
doc.initY = parseInt(frm.style.top);
doc.drag = true;
_event = null;
};
frmCont.getElementById("drag").onmousemove = function(){
var _event = this.document.parentWindow.event;
var doc = this.document;
var frm = parent.document.getElementById(this.frmid);
if(doc.drag){
frm.style.left = _event.x - doc.posX + doc.initX;
frm.style.top = _event.y - doc.posY + doc.initY;
doc.initX = parseInt(frm.style.left);
doc.initY = parseInt(frm.style.top);
}
_event = null;
};
frmCont.getElementById("drag").onmouseup = function(){
var doc = this.document;
doc.posX = 0;
doc.posY = 0;
doc.initX = 0;
doc.initY = 0;
if(doc.drag == true){
doc.drag =false;
}
};
frmCont.getElementById("drag").onmouseout = function(){
var doc = this.document;
doc.posX = 0;
doc.posY = 0;
doc.initX = 0;
doc.initY = 0;
if(doc.drag == true){
doc.drag = false;
}
};
}
}

document.body.appendChild(frm);
}
function  htmlEditor(){
var frm = document.getElementById("ifrm");
frm.style.display = '';
var iframeTextContent = '';
iframeTextContent += ' <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
iframeTextContent += ' <html xmlns="http://www.w3.org/1999/xhtml">';
iframeTextContent += ' <head>';
iframeTextContent += ' <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />';
iframeTextContent += ' </head>';
iframeTextContent += ' <div id="drag" style="position:absolute;height:160px;width:460px;z-index:10001;top:0;">'
iframeTextContent += ' <body>';
iframeTextContent += ' <table id="t">';
iframeTextContent += ' <tr>';
iframeTextContent += ' <td>Name </td>';
iframeTextContent += ' <td> <input type="text" value="" /> </td>';
iframeTextContent += ' </tr>';
iframeTextContent += ' <tr>';
iframeTextContent += ' <td>Email </td>';
iframeTextContent += ' <td> <input type="text" value="" /> </td>';
iframeTextContent += ' </tr>';
iframeTextContent += ' <tr>';
iframeTextContent += ' <td> <input type="button" id="btGo" value="Go" /> </td>';
iframeTextContent += ' </tr>';
iframeTextContent += ' </table>';
iframeTextContent += ' </body>';
iframeTextContent += ' </div>';
iframeTextContent += ' </html>';
frm.contentWindow.document.designMode = 'off';
frm.contentWindow.document.open();
frm.contentWindow.document.write(iframeTextContent);
frm.contentWindow.document.close();

var objGo = frm.contentWindow.document.getElementById("btGo");
objGo.attachEvent("onclick",function(){HideIframe(frm);});
}
function HideIframe(frm){
frm.style.display = 'none';
}
</script>
</head>

<body onload="createIframe()">
<input type="button" id="tt" name="tt" value="Click" onclick="htmlEditor()" />
</body>
</html>

 

示例2

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Untitled Document </title>
<script>
function createIframe(){
var objDiv = document.createElement("DIV");
objDiv.id = "div1";
objDiv.name = "div1";
objDiv.style.width = "480px";
objDiv.style.height = "200px";
objDiv.style.left = document.body.scrollLeft + event.clientX + 50;
objDiv.style.top = document.body.scrollTop + event.clientY - 180;
objDiv.style.position = "absolute";
objDiv.innerHTML = ' <div id="drag" style="position:absolute;height:20px;width:100%;z-index:10001;top:0; background-color:#0033FF;cursor:move ;"> </div>';
objDiv.style.border = "solid #0033FF  3px;";
objDiv.style.display = 'none';

var frm = document.createElement("iframe");
frm.id = "ifrm";
frm.name = "ifrm";
frm.style.position = "absolute";
frm.style.width = "100%";
frm.style.height = 180;
frm.style.top = 20;
frm.style.display = '';
frm.frameborder=0;
objDiv.appendChild(frm);
document.body.appendChild(objDiv);
var objDrag = document.getElementById("drag");
var drag = false;
objDrag.attachEvent("onmousedown",startDrag);
function startDrag(){
if(event.button == 1 && event.srcElement.tagName.toUpperCase() =="DIV"){
objDrag.setCapture();
objDrag.style.background = "#0000CC";
drag = true;
}
};
objDrag.attachEvent("onmousemove",Drag);
function Drag(){
if(drag){
var oldwin = objDrag.parentNode;
oldwin.style.left = event.clientX - 100;
oldwin.style.top = event.clientY - 10;
}
};
objDrag.attachEvent("onmouseup",stopDrag);
function stopDrag(){
objDrag.style.background = "#0033FF";
objDrag.releaseCapture();
drag = false;
};
}
function htmlEditor(){
var frm = document.getElementById("ifrm");
var objDiv = document.getElementById("div1");
objDiv.style.display = '';
var iframeTextContent = '';
iframeTextContent += ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">';
iframeTextContent += ' <html xmlns="http://www.w3.org/1999/xhtml">';
  iframeTextContent += ' <head>';
  iframeTextContent += ' <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />';
  iframeTextContent += ' </head>';
iframeTextContent += ' <body>';
iframeTextContent += ' <table>';
iframeTextContent += ' <tr>';
iframeTextContent += ' <td>Name </td>';
  iframeTextContent += ' <td> <input type="text" value="" /> </td>';
  iframeTextContent += ' </tr>';
  iframeTextContent += ' <tr>';
  iframeTextContent += ' <td>Email </td>';
  iframeTextContent += ' <td> <input type="text" value="" /> </td>';
  iframeTextContent += ' </tr>';
  iframeTextContent += ' <tr>';
  iframeTextContent += ' <td> <input type="button" id="btGo" value="Go" /> </td>';
  iframeTextContent += ' </tr>';
  iframeTextContent += ' </table>';
  iframeTextContent += ' </body>';
  iframeTextContent += ' </html>';
frm.contentWindow.document.designMode = 'off';
  frm.contentWindow.document.open();
  frm.contentWindow.document.write(iframeTextContent);
  frm.contentWindow.document.close();

var objGo = frm.contentWindow.document.getElementById("btGo");
  objGo.attachEvent("onclick",function(){HideIframe(objDiv);});
}

function HideIframe(objDiv){
  objDiv.style.display = 'none';
}
</script>
</head>

<body onload="createIframe()">
<input type="button" id="tt" name="tt" value="Click" onclick="htmlEditor()" />
</body>
</html>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章