在HTML,Javascript,.innerHTML,开关和案例中引用问题

时间:2012-10-26 19:55:52

标签: javascript html

我正在修改一个websense块页面,以包含一些基于变量的函数:$ * WS_BLOCKREASON * $。我知道这个变量的潜在输出,我希望有一个特定的功能。

问题是该页面甚至没有将默认大小写传递给'&lt;'div'&gt;'内容。基本上我需要<div id="helpDiv">的内容是一整套文本,包括按钮。下面的脚本:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Access to this site is blocked</title>
<link rel="stylesheet" href="/en/Custom/master.css" type="text/css">
<script type="text/javascript" language="javascript" src="/en/Default/master.js"></script>
<script type="text/javascript" language="javascript" src="/en/Default/base64.js"></script>
<script type="text/javascript" language="javascript" src="/en/Custom/security.js"></script>
<style type="text/css">
        .style1
        {
            width: 130px;
           height: 70px;
        }
    </style>
</head>
<body>

<!--[if lt IE 7]> <div style="width: 725px; height: 381px;"> <![endif] -->
        <img alt="BHI" class="style1" 
            src="/en/Custom/other.gif" /><br />
        <br />
        <br />
<div style="border: 1px solid #285EA6;width: 99.5%; max-width: 915px; overflow: hidden; margin-left: 1px; background-color: #EEF2F7;">
    <iframe src="$*WS_BLOCKMESSAGE_PAGE*$*WS_SESSIONID*$" title="BHI_BLOCK" 
        name="ws_block" frameborder="0" scrolling="no" 
        style="width:100%; height: 200px; margin-bottom: 0px;">
    </iframe>
<hr />
    <!-- onload=function() possible fix -->
    <script type="text/javascript">
    var blockReason=$*WS_BLOCKREASON*$;

    switch (blockReason)
        {
        case 'This Websense category is filtered: <b>Uncategorized</b>.':
            document.getElementById('helpDiv').innerHTML='<p style="margin-left: 10px">Help:&nbsp;&nbsp;&nbsp;&nbsp;<INPUT TYPE="button" VALUE="Submit UNCATEGORIZED website to Websense" onClick="parent.location=\'mailto:suggest@websense.com?subject=Uncategorized Website&body=Please review and correctly categorize the website that is listed below:%0A%0A' + $*WS_URL*$ + '%0A%0AThank you.\'"></p>\
            <hr />\
            <p style="margin-left: 64px">Clicking on the above button will open your mail client to send an e-mail to Websense for recategorization of the above site.</p>\
            <p style="margin-left: 64px">You will receive a confirmation e-mail and a case number from Websense indicating your request is proccessing.</p>\
            <p style="margin-left: 64px">Please note the response time for your request will vary. Allow to three to four (3-4) hours for updates to take effect once approved.</p>\
            <p style="margin-left: 64px">If you have any questions, please contact SOLV at <a href=tel:+18772222222>+1 877 2222222<a/> or <a href=http://solv:8093/CAisd/pdmweb.exe?OP=JUST_GRONK_IT+HTMPL=about.htmpl target="_blank">this link.</a></p>';
        break;

        case 'This Websense category is filtered: <b>Parked Domain</b>.':
            document.getElementById('helpDiv').innerHTML='<p>Parked domain</p>';
        break;

        default:
            document.getElementById('helpDiv').innerHTML='<p>No Block message help.</p>';
        }
    </script>
    <div frameborder="0" scrolling="no" style="width:100%; height: auto; margin-bottom: 0px;" id="helpDiv">
    </div>
<iframe src="$*WS_BLOCKOPTION_PAGE*$*WS_SESSIONID*$" name="ws_blockoption" 
        frameborder="0" scrolling="no" style="width:100%; height: auto;">
        <p>To enable further options, view this page with a browser that supports iframes</p>
    padding: 2px 0px;">
        <div style="clear: both; overflow: hidden; height:1px;"></div>
    </div>
</div>
<!--[if lt IE 7]> </div> <![endif]-->
<div id="light" class="white_content"></div>
<div id="fade" class="black_overlay"></div>
</body>
</html>

2 个答案:

答案 0 :(得分:0)

你在这条线路上逃脱不当:

    document.getElementById('helpDiv').innerHTML='<p style="margin-left: 10px">Help:&nbsp;&nbsp;&nbsp;&nbsp;<INPUT TYPE="button" VALUE="Submit UNCATEGORIZED website to Websense" onClick="parent.location="'\\"mailto:suggest@websense.com?subject=Uncategorized Website&body=Please review and correctly categorize the website that is listed below:%0A%0A$*WS_URL*$%0A%0AThank you."'\\"></p>

应该是(在onClick之后):

"parent.location=\'mailto:suggest@websense.com?subject=Uncategorized Website&body=Please review and correctly categorize the website that is listed below:%0A%0A' + $*WS_URL*$ + '%0A%0AThank you.\'"></p>\

纠正逃脱的小提琴:http://jsfiddle.net/3UxCc/ 它有效。

修改
看起来您的$*WS变量是标记。在这种情况下,您要为某些内容分配blockReason,但除非您的WebSense变量包含引号(它不是btw),否则您的分配看起来像:

var blockReason = other;  

由于周围没有引号,它认为other是一个变量而不是字符串文字。您需要将其括在引号中,如:

var blockReason = '$*WS_BLOCKREASON*$';

这将把它建立为交换机能够使用的字符串文字。其他任何东西都是一个会导致错误的错误变量。

答案 1 :(得分:0)

试试这个。你有一些不正确的逃避......

该部分特别是在案例第一行的onClick周围

 case 'This Websense category is filtered: <b>Uncategorized</b>.':
    document.getElementById('helpDiv').innerHTML='<p style="margin-left: 10px">Help:&nbsp;&nbsp;&nbsp;&nbsp;<INPUT TYPE="button" VALUE="Submit UNCATEGORIZED website to Websense" onClick="parent.location=\'mailto:suggest@websense.com?subject=Uncategorized Website&body=Please review and correctly categorize the website that is listed below:%0A%0A' + $*WS_URL*$ + '%0A%0AThank you.\'"></p>\
    <hr />\
    <p style="margin-left: 64px">Clicking on the above button will open your mail client to send an e-mail to Websense for recategorization of the above site.</p>\
    <p style="margin-left: 64px">You will receive a confirmation e-mail and a case number from Websense indicating your request is proccessing.</p>\
    <p style="margin-left: 64px">Please note the response time for your request will vary. Allow to three to four (3-4) hours for updates to take effect once approved.</p>\
    <p style="margin-left: 64px">If you have any questions, please contact SOLV at <a href=tel:+18772097658>+1 877 209 7658<a/> or <a href=http://solv:8093/CAisd/pdmweb.exe?OP=JUST_GRONK_IT+HTMPL=about.htmpl target="_blank">this link.</a></p>';
break;

<强>更新

刚刚在jsFiddle中玩过我得出的结论是你对helpDiv的引用无效..

如果您使用某些警报替换所有这些警报,您的交换机将达到默认值。它正在消亡,因为你的getElementById有问题。也许该元素没有ID helpDiv?

这是一个非常精简的版本

http://jsfiddle.net/5wvC3/

这是另一个小提琴 - 并在最后一个上进行更新,表明代码主要起作用。您的HTML存在问题

http://jsfiddle.net/5wvC3/1/