使用javascript查找参数 [英] find parameter using javascript

查看:72
本文介绍了使用javascript查找参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们...

我在tryng 2中找到URL中的参数,如果发现我想用编辑的URL替换当前URL.但是它不起作用.你能帮我怎么做....

这是我的代码

Hi friends...

i m tryng 2 find parameter in url, and if it found i want to replace the current URL with edited URL.but its not working.Can u please help me how to do this....

Here is my code

<html>
<head>
<script type="text/javascript">

function appendkeycode()
{
window.location.href="https://tools.aaa.com/gdrp/coiga/showsurvey.do?surveyCode=7189&keyCode=000038167&gId=#pf:CONTACT_ID#";
// Declare Variables
 var linkurl = 'https://secure.lomadee.com/at/actionlog';
 var linktext = '&adv=5742&country=AR&event=12583';
 var adminkeycode='000056432'

       var KeyCode_pattern= /^[0-9]{9}$/
       var pageurl = window.location.href;
	   var KeyCode="";
	     if(pageurl.indexOf("KeyCode=")!= -1)
            {
                 KeyCode=pageurl.substr(pageurl.indexOf("KeyCode=")+4);
                 var checkextraval = KeyCode.search("&");
                  if(checkextraval != -1)
                  KeyCode=Keycode.split("&")[0];
                  window.location.replace(linkurl + '?transaction=' + KeyCode + linktext );    
            }
	

}


</script>
</head>
<body>

<input type="button" id="btnClk" value="Register Now"  önClick=appendkeycode()>


</body>
</html>



更新:
我只想使用html/css和javascript.所以请库尔告诉我我该如何解决这个问题...我正在重拍我的任务..假设我单击一个按钮/链接/图像等,它将打开https://tools.aaa.com/gdrp/coiga/showsurvey.do?surveyCode=7189&keyCode=000038167&gId=#pf:CONTACT_ID#现在我要在浏览器处理打开上述链接时调用某些javascript函数,该函数会在处理链接中搜索关键代码(如果是)找到用(window.location.replace(linkurl +``?transaction =''+ KeyCode + linktext);)替换过程链接...)...否则它将显示键码值并显示具有无效键码值的链接.表示我想更改html中的innerhtml值...
有问题或评论吗?



Update:
I want to make it using html/css and javascript only. so please couls u plz tell me how can i proceed for this problem... i m repatng my questons.. suppose i click one button/link/images etc it will open https://tools.aaa.com/gdrp/coiga/showsurvey.do?surveyCode=7189&keyCode=000038167&gId=#pf:CONTACT_ID# now i want when the browser is processing to open the above link,some javascript function will call,which search for keycode in processing link, if it is found replace the proceesing link with( window.location.replace(linkurl + ''?transaction='' + KeyCode + linktext );)...otherwise it will show the keycode value nd show the link with defult keycode value. means i want to change the innerhtml value in html...
Have a Question or Comment?

推荐答案

/ var pageurl = 窗口.位置 .href ; var KeyCode = " ; 如果(pageurl.indexOf(" )!= -1) { KeyCode = pageurl.substr(pageurl.indexOf(" )+ 4);; var checkextraval = KeyCode.search(" ); 如果(checkextraval!= -1) KeyCode = Keycode.split(" )[ 0 ]; 窗口.位置 .replace(链接网址+ ' ?transaction =' + KeyCode + linktext); } } </script> </ 头部 > <身体> < input type = " id = " btnClk" value = 立即注册"önClick= appendkeycode()> </ 正文 > </ html >
/ var pageurl = window.location.href; var KeyCode=""; if(pageurl.indexOf("KeyCode=")!= -1) { KeyCode=pageurl.substr(pageurl.indexOf("KeyCode=")+4); var checkextraval = KeyCode.search("&"); if(checkextraval != -1) KeyCode=Keycode.split("&")[0]; window.location.replace(linkurl + '?transaction=' + KeyCode + linktext ); } } </script> </head> <body> <input type="button" id="btnClk" value="Register Now" önClick=appendkeycode()> </body> </html>



更新:
我只想使用html/css和javascript.所以请库尔告诉我我该如何解决这个问题...我正在重拍我的任务..假设我单击一个按钮/链接/图像等,它将打开https://tools.aaa.com/gdrp/coiga/showsurvey.do?surveyCode=7189&keyCode=000038167&gId=#pf:CONTACT_ID#现在我要在浏览器处理打开上述链接时调用某些javascript函数,该函数会在处理链接中搜索关键代码(如果是)找到用(window.location.replace(linkurl +``?transaction =''+ KeyCode + linktext);)替换过程链接...)...否则它将显示键码值并显示具有无效键码值的链接.表示我想更改html中的innerhtml值...
有疑问或评论吗?



Update:
I want to make it using html/css and javascript only. so please couls u plz tell me how can i proceed for this problem... i m repatng my questons.. suppose i click one button/link/images etc it will open https://tools.aaa.com/gdrp/coiga/showsurvey.do?surveyCode=7189&keyCode=000038167&gId=#pf:CONTACT_ID# now i want when the browser is processing to open the above link,some javascript function will call,which search for keycode in processing link, if it is found replace the proceesing link with( window.location.replace(linkurl + ''?transaction='' + KeyCode + linktext );)...otherwise it will show the keycode value nd show the link with defult keycode value. means i want to change the innerhtml value in html...
Have a Question or Comment?


首先,更改函数开头的位置将使其执行方式降低-不确定.不会以这种方式工作.您应该重新考虑要实现的逻辑.
这是一个JQuery插件,您可以用来解析和处理url字符串: https://github.com/allmarkedup/jQuery-URL-Parser/blob/master/README.md [
First of all, changing the location at the very beginning of the function will drop it''s execution - in an undefined way. Won''t work this way. You should reconsider the logic you want to implement.
Here is a JQuery plugin, you can use to parse and manipulate url strings: https://github.com/allmarkedup/jQuery-URL-Parser/blob/master/README.md[^]


这篇关于使用javascript查找参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆