2012-10-27 67 views
0

如何用vbscript提取iframe名稱?例如像如果我的字符串值是用vbscript獲取iframe名稱

<DIV style="MARGIN-TOP: 0px; WIDTH: 670px; HEIGHT: 210px; VISIBILITY: visible; MARGIN-LEFT: -335px; TOP: 48px" id=TB_window><DIV id=TB_title> <DIV id=TB_ajaxWindowTitle>Add Media</DIV> <DIV id=TB_closeAjaxWindow><A id=TB_closeWindowButton title=Close href="#" jQuery172014112867239284427="140"><IMG src="http://www.gorgeoushentai.com/wp-includes/js/thickbox/tb-close.png"></A></DIV></DIV><IFRAME style="WIDTH: 670px; HEIGHT: 180px" id=TB_iframeContent onload=tb_showIframe() src="http://www.gorgeoushentai.com/wp-admin/media-upload.php?post_id=168&amp;" frameBorder=0 name=TB_iframeContent656 hspace=0>This feature requires inline frames. You have iframes disabled or your browser does not support them.</IFRAME></DIV> 

然後將提取的價值將是TB_iframeContent656

我試圖寫在VBScript代碼,但它不工作

<script type="text/vbscript"> 
box="<DIV style=""MARGIN-TOP: 0px; WIDTH: 670px; HEIGHT: 210px; VISIBILITY: visible; MARGIN-LEFT: -335px; TOP: 48px"" id=TB_window><DIV id=TB_title> <DIV id=TB_ajaxWindowTitle>Add Media</DIV> <DIV id=TB_closeAjaxWindow><A id=TB_closeWindowButton title=Close href=""#"" jQuery172014112867239284427=""140""><IMG src=""http://www.gorgeoushentai.com/wp-includes/js/thickbox/tb-close.png""></A></DIV></DIV><IFRAME style=""WIDTH: 670px; HEIGHT: 180px"" id=TB_iframeContent onload=tb_showIframe() src=""http://www.gorgeoushentai.com/wp-admin/media-upload.php?post_id=168&amp;"" frameBorder=0 name=TB_iframeContent656 hspace=0>This feature requires inline frames. You have iframes disabled or your browser does not support them.</IFRAME></DIV>" 

data = box.document.getElementById("TB_iframeContent").name 
document.write(data) 
</script> 
+0

嘗試'document.getElementById(「TB_iframeContent」)。name' –

+0

你能幫我寫代碼嗎?我在第一篇文章中添加了我的代碼 –

回答

0

有你的代碼有兩件事是錯誤的:

  1. A string對象不包含名爲document的值/方法。
  2. 當你執行像這樣在創建文檔之前的代碼會被執行等等之類的東西IFRAME不會存在,因此顯然這樣的元素不能被發現。

看一下下面的代碼工作的例子。首先它會查看實際頁面而不是stringWindowLoad函數確保在執行代碼之前加載頁面。

<html> 
<head> 
<script type="text/vbscript"> 
Set window.onload = GetRef("WindowLoad") 
Function WindowLoad 
    Dim somediv 
    Set somediv = document.getElementById("someid") 

    Dim data 
    Set data = document.getElementById("TB_iframeContent") 
    if data Is Nothing then 
     MsgBox("element does not exist") 
    else 
     somediv.InnerHTML = data.name 
    end if 

End Function 
</script> 
</head> 

<body> 
<!-- Some ID for testing purposes --> 
<div id="someid"></div> 
<!-- The DIV with the iframe --> 
<div style="MARGIN-TOP: 0px; WIDTH: 670px; HEIGHT: 210px; VISIBILITY: visible; MARGIN-LEFT: -335px; TOP: 48px" id=TB_window> 
    <div id=TB_title> 
    <div id=TB_ajaxWindowTitle>Add Media</DIV> 
    <DIV id=TB_closeAjaxWindow><A id=TB_closeWindowButton title=Close href="#" jQuery172014112867239284427="140"> 
     <IMG src="http://www.gorgeoushentai.com/wp-includes/js/thickbox/tb-close.png"></A> 
    </DIV> 
    </DIV> 
    <IFRAME style="WIDTH: 670px; HEIGHT: 180px" id=TB_iframeContent onload=tb_showIframe() src="http://www.gorgeoushentai.com/wp-admin/media-upload.php?post_id=168&amp;" frameBorder=0 name=TB_iframeContent656 hspace=0>This feature requires inline frames. You have iframes disabled or your browser does not support them.</IFRAME> 
    </DIV> 
</body> 
</html>