<a href= "javascript:window

来源:互联网 发布:现代网络女作家排行榜 编辑:程序博客网 时间:2024/04/29 04:24

我有一个button,想通点该button打开一个连接地址,或用 <a   href= "javascript:window.location= '连接地址 '; "> <input   type= "button "   ...   /> </a> ,连接中包含空格和&,

问题:1.在IE中打不开连接地址,FireFox   下正常,我用的是 <a> ,非button的onclick事件
2.为什么在safari下,参数是乱码

连接地址例如:FF:
http://www.xxx.net/service/forums/newthread.asp?title=Cute%20FTP%20Professional%208.0.7&p=%D0%E9%C4%E2%D6%F7%BB%FA
Safari:
http://www.xxx.net/service/forums/newthread.asp?title=Cute%20FTP%20Professional%208.0.7&p=???????

我的document:
<!DOCTYPE   html   PUBLIC   "-//W3C//DTD   XHTML   1.0   Transitional//EN "   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

 

回答===========================

 

不明白为什么你会要在Button外面加A标签,Button的Onclick的事件会比A的href好用很多。如果你一定想用这种方法来完成功能,这个Button最好不要放在Form里,要不可能会运行Form的Submit事件。

如果你一定要这样完成,建议写一个函数:

function   test()   {
    javascript:window.location   =   'http://www....D0%E9%C4%E2%D6%F7%BB%FA ';
}

然后在A的href中写:“javascript:test();”来调用它。

如果你要动态参数,一定要用encodeURIComponent来对参数进行编码,要不中间的特殊字符可能会打断URL的解析。
===================================

<a   id= 'jumpLink '   href= "javascript:window.location= '连接地址 '; "> </a> <input   type= "button "   onClick= 'document.all.jumpLink.click(); '   ...   />

原创粉丝点击