antonyfal Posted September 28, 2011 Share Posted September 28, 2011 I'm changing all the links on my site from: //example current link is: <a href="http://www.xxxxx.com/subfolder/somefile.php/?someoption&somethingelse">click</a> //If you put the mouse over the link it is displayed in the address bar. i don't want site users to see this links. //i want to make something like this: <a href="javascript:void(0);" onClick="openUrl(\"http://www.xxxxx.com/subfolder/somefile.php/?someoption&somethingelse\",_self);">click</a> // so now the user only see the javasript:void(0); and not the link. but my code is not working, and i have to many links and pages to make a javascript function for redirecting the url onclick for every link. is there a universal function to achieve the goal that i want? Quote Link to comment https://forums.phpfreaks.com/topic/248030-change-href-and-add-onclick-all-in-one-line/ Share on other sites More sharing options...
antonyfal Posted September 28, 2011 Author Share Posted September 28, 2011 Ok i got it to work like this: <a href="javascript:void(0);" onClick="javascript:q=(document.location.href);void(open('http://www.xxxxx.com/subfolder/somefile.php/?someoption&somethingelse?url='+escape(q),'_self',''));">click</a> if anyone knows a better way? please post here. also it seems that the "q" can remain "q" regardles of the amount of links on a page.. It doesnt have to change to q for one link, z for another b for another etc etc etc.. Quote Link to comment https://forums.phpfreaks.com/topic/248030-change-href-and-add-onclick-all-in-one-line/#findComment-1273562 Share on other sites More sharing options...
antonyfal Posted September 28, 2011 Author Share Posted September 28, 2011 OK!! sorry not solved. This code only works on some links.. Is there a better way to have: onclick="openUrl('http://xxx.com/subfolder/index.php/?someoption.html'); i just basically want to move the href link into the onclick and the href must = javascript:void(0); Can anyone do this is please? Quote Link to comment https://forums.phpfreaks.com/topic/248030-change-href-and-add-onclick-all-in-one-line/#findComment-1273595 Share on other sites More sharing options...
nogray Posted September 28, 2011 Share Posted September 28, 2011 try <a href="#" onclick="location.href='my_url';"> Quote Link to comment https://forums.phpfreaks.com/topic/248030-change-href-and-add-onclick-all-in-one-line/#findComment-1273615 Share on other sites More sharing options...
antonyfal Posted September 28, 2011 Author Share Posted September 28, 2011 Thanks for the replying: i also got it to work also with this code: onclick=window.opener.document.location.href='http://www.xxx.com/';>Click</a>"; but i will try your code looks simpler and post back Quote Link to comment https://forums.phpfreaks.com/topic/248030-change-href-and-add-onclick-all-in-one-line/#findComment-1273630 Share on other sites More sharing options...
antonyfal Posted September 28, 2011 Author Share Posted September 28, 2011 Thanks nogray. Your code is better works with the "#" and the "javascript:void(0);" ill use your code much easier to implement. best regards Antony Quote Link to comment https://forums.phpfreaks.com/topic/248030-change-href-and-add-onclick-all-in-one-line/#findComment-1273632 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.