Click here to Skip to main content
16,012,223 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
JavaScript
<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>


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?
Posted
Updated 22-Sep-12 2:14am
v4
Comments
[no name] 21-Sep-12 15:04pm    
"its not working" is not a very helpful decription of any kind of a problem. Does the code not run? Do you get the wrong index? Did your code format the hard drive? Did the code make your car explode?

1 solution

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[^]
 
Share this answer
 
v3
Comments
rajdeep kumar 22-Sep-12 7:29am    
Hi Zoltán Zörgő, thanks for your answer,
but the link u hv gvn for guide is using jquery, actually 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...
Zoltán Zörgő 22-Sep-12 8:13am    
First of all, JQuery is Javascript. It is a Javascript library that's making your life easier. Where you use Javascript, you can use JQuery also.
And now about your logic: you want to intercept the location changes like a hook? Otherwise it makes no sense to me: why do you want to change the url on client side why aren't you generating the good one?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900