通过js以超链接的形式访问jsp或访问servlet

    技术2022-05-20  47

    在做项目的过程中,要在input按钮上做超链接,直接给input 加链接后,在火狐里面点击,会连续打开两个窗口,IE下没有看,记得以前见过哪个网站用JS新窗口,代码还挺简洁,在网上查了下,找到了,给input加onclick事件 οnclick=”javascript:window.open(’http://www.y7l8.com’)”

    还有一种比较复杂的,定义一个新的窗口出来

    还有一种

    <script   LANGUAGE=”JavaScript”>

    <!–

    function   openwin()   {

    //window.open(’http://www.y7l8.com’,'Y7L8-BLOG’,'height=800,   width=600,   toolbar   =no,   menubar=no,   scrollbars=no,   resizable=no,   location=no,   status=no’)

    window.open(’http://www.y7l8.com’,'Y7L8-BLOG’)

    }

    –>

    </script>

    调用就onclick   =   “openwin()”

    例子:<input   button   value=”打开新窗口”     onclick   =   “openwin()”>

    另一种简介,多功能的写法

    <input type=”button” Value=”打开新窗口”

    ONCLICK=”window.open(’http://www.y7l8.com’,'Sample’,'toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=no,resizable=no,copyhistory=yes,width=300,height=200,left=100,top=100′)”>

    下面解释一下这些参数的说明

    toolbar=yes, 显示工具条

    location=yes,显示网址栏

    directories=no,导航条

    status=no,状态条

    menubar=yes,菜单

    scrollbars=yes,滚动条

    resizable=no,是否可以改变大小

    copyhistory=yes,历史按钮

    width=300,宽

    height=200′高

    left=100,距离左边100

    top=100,距离顶端100

    还有一种方法是在本窗口打开的方法:

    <input type=”button” Value=”在本窗口打开”

    ONCLICK=”window.location.href='http://www.baidu.com';"/>

    通过js以超链接的形式访问servlet:

     

    <script type="text/javascript">               function deleteArticle(id,typeid,page){                   if(confirm("确定要删除你以前辛勤的成果吗?")){                       window.location.href="/10/ArticleFox?type=3&id="+id+"&typeId="+typeid+"&Page="+page;                   }               }           </script>  

    //调用js

    <a  href="javascript:deleteArticle('<%=af.getId()%>','<%=typeId %>','<%=Page %>')" >删除</a>  

    或者写成JavaScript脚本的形式,在调用。用这种方式,也可以使用链接提交表单数据。有兴趣的朋友可以在网上搜索到相关的代码,写法都是相似的!


    最新回复(0)