JS手动指定Form的action -(做SEO时碰到的疑难杂症-1)

刚刚测试人员发现,页面在Firefox里提交数据时出错,
检查了一下,发现是一段JS代码在写的时候,没有考虑到IE与Firefox之间的区别
IE中document.aspnetForm.action在Firefox中不认。
查了些JS 资料后,修改如下
原代码:
         var path= document.aspnetForm.action;
         document.aspnetForm.action='/'+path;

修改后代码:
       var theForm = document.forms['aspnetForm'];
        if(navigator.appName == 'Netscape')
        {           
            var act = theForm.action;
            var inde = act.lastIndexOf("/");
            var leng =act.length;
            var filename = act.substring(inde ,leng);
            theForm.action='http://'+window.location.host+filename;
        }
        else if (theForm) {
             theForm = document.aspnetForm;
             var path= theForm.action;
             theForm.action='/'+path;
        }

调试JS过程中,发现Js中的substring方法与C#中的SubString方法的不同之处

js substring方法
function substring(start : Number, end : Number) : String
参数
start  必选。从 0 开始的索引整数,指示子字符串的起始位置。  
end  必选。从 0 开始的索引整数,指示子字符串的结束位置。  
从start开始,截至end索取位置。

C#SubString方法
Function substring (string startindex,string number)
从startindex开始截取number个数量的字符。

以下属于引用---------好东西就应该记下来!
设置或获取对象指定的文件名或路径。
<script>
alert(window.location.pathname)
</script>

设置或获取整个 URL 为字符串。
<script>

alert(window.location.href);
</script>
设置或获取与 URL 关联的端口号码。
<script>
alert(window.location.port)
</script>

设置或获取 URL 的协议部分。
<script>
alert(window.location.protocol)
</script>

设置或获取 href 属性中在井号“#”后面的分段。
<script>
alert(window.location.hash)
</script>

设置或获取 location 或 URL 的 hostname 和 port 号码。
<script>
alert(window.location.host)
</script>

设置或获取 href 属性中跟在问号后面的部分。
<script>
alert(window.location.search)
</script>

posted @ 2008-02-26 17:36  李帅斌-Memory  阅读(2938)  评论(0编辑  收藏  举报