如何在jsp中使用tinybox

时间:2013-07-26 11:47:34

标签: java jquery ajax jsp

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <title>JSP Page</title>

    <script type="text/javascript" src="tinybox.js"></script>

</head>

<body>

    <label>Name :</label><input type="text" id="name" onclick="tiny();"/>

      <script type="text/javascript">

        function tiny(show)
        {
            TINY.box().show(ajax.html,show,300,150,true,500) ;  
        }
      </script>
</body>

以上代码在jsp.please中不起作用帮助我如何在jsp.ajax.html页面中使用tinybox已存在于此页面的同一位置。

2 个答案:

答案 0 :(得分:0)

这可能有两个原因

1。您需要使用 request.getContextPath()来获取上下文路径,因为您正在使用 JSP 并需要追加那到ajax.html

以下是它的外观片段,

TINY.box()。show('&lt;%= request.getContextPath()%&gt; /ajax.html','show',300,150,true,500);

2。您在“ajax.html”中缺少引号。当尝试使用没有引号的ajax.html时,Javascript会抛出错误。

答案 1 :(得分:0)

经过多次尝试,我得到了一些东西。

它存在两个版本的框架。

此处 * Tinybox 1的代码 *

<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>JSP Page</title>
<link rel="stylesheet" href="http://sandbox.scriptiny.com/tinybox/style.css" />
<script type="text/javascript" src="http://sandbox.scriptiny.com/tinybox/tinybox.js"></script>
<script type="text/javascript">
function tiny(show)
{
 TINY.box.show("ajax.html",show,300,150,true,5);  
}
</script>
</head>
<body>
 <label>Name: </label><input type="text" id="name" onclick="tiny(true)"/>
</body>
<html>

如果变量show的值为真(或1),则似乎tinybox希望通过iframe包含给定文件。我的IE9,FF21和Chrome浏览器可以打开文件(浏览器抱怨访问验证)。在对面,有效的外部URL确实有效。

这里的代码为 * Tinybox 2 *

<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>JSP Page</title>
  <link rel="stylesheet" href="http://sandbox.scriptiny.com/tinybox2/style.css" />
  <script type="text/javascript" src="http://sandbox.scriptiny.com/tinybox2/tinybox.js"></script>
  <script type="text/javascript">
    function tiny(show)
    {
      TINY.box.show({iframe:'ajax.html',width:300,height:150})
     }
  </script>
</head>
<body>
 <label>Name: </label><input type="text" id="name" onclick="tiny(true)"/>
</body>
<html>

这个版本确实很有效。