0

如何使用 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>
4

1 回答 1

0

您的代码有两个问题:

  1. string对象不包含名为 document 的值/方法。
  2. 当你像这样执行它时,代码将在创建文档之前执行,所以像 iframe 这样的东西还不存在,所以显然找不到这样的元素。

查看下面的代码以获取工作示例。首先,它将查看实际页面而不是string. 该WindowLoad函数确保在执行代码之前加载页面。

<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> 
于 2012-10-30T17:21:38.617 回答