0

I have a sharepoint page on which multiple hyperlinks added. due to browser encoding some of them are not redirecting correctly, thus I have to use onclick event for all of them using javascript inline. so while giving hyperlink we can pass URL to inline onclick function. and then we can use windows.locatoin.href in that function.

In content editor webpart its something like :

<p <a href="javascript:onclick=Myfunction('http://www.bing.com');"> bing</a></p>
<p <a href="javascript:onclick=Myfunction('http://www.yahoo.com');"> google</a></p>
<p <a href="javascript:onclick=Myfunction('http://www.facebook.com');"> facebook</a></p

<script type="text/javascript">
MyFunction(url){

$(document).ready(function(){

       window.location.href ='url';

});

}
</script>

I am missing something, can anyone plz help me out. i have added google, bing and facebook for an example

2

Try replacing

<a href="javascript:onclick=MyFunction('http://www.bing.com');">

with

<a href="javascript:MyFunction('http://www.bing.com')">

or

<a href="#" onclick="MyFunction('http://www.bing.com')">

Not that you also have quotes around the url-parameter that you should not, and that your script do require jQuery to be present on the page (not sure why you even need this at all). Also you spelled MyFunction with a lowercase f in your link (it is case sensitive):

MyFunction(url){

    $(document).ready(function(){ /* Uses jQuery here */

       window.location.href = url; /* You had quotes around url */

    });

}
2
  • yes ..I tried that way also. Am I doing any mistake in script? – Rajeev K Mar 5 '14 at 13:43
  • See my updated answer – Robert Lindgren Mar 5 '14 at 13:54
0

Why are you using jquery for this? No not need what so ever.

<p> <a href="javascript:void(0)" onclick="MyFunction('http://www.bing.com');"> bing</a></p>

<script type="text/javascript">
MyFunction(url){
    window.location.href = url;
}
</script>
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.