Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have created custom ASPX page in Visual studio for my SharePoint application. I want to use JavaScript function on this custom page like this:

function ChangeLanguage(value) {
    var today = new Date();
    var oneYear = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000);
    var url = window.location.href;
    document.cookie = "lcid=" + value + ";path=/;expires=" + oneYear.toGMTString();
    window.location.href = url;
}


<a href="javascript:ChangeLanguage(1053)"></a>

But, its not allowed to put JavaScript code in custom page. Is there any possibility to do this ?

share|improve this question
    
It is definately possible to include javascript on your aspx page. However, if this is all you are doing, you could also get away with doing it inside a ContentEditor web part. –  andrew.petersen15 Dec 17 '12 at 21:15
add comment

1 Answer 1

up vote 0 down vote accepted

Instead of writing the call in href, call it onclick event

function ChangeLanguage(value) {
    var today = new Date();
    var oneYear = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000);
    var url = window.location.href;
    document.cookie = "lcid=" + value + ";path=/;expires=" + oneYear.toGMTString();
    window.location.href = url;
}


<a href="#" onclick="javascript:ChangeLanguage(1053);">Change Language</a>
share|improve this answer
    
Ok. But problem is not on <a href="javascript:ChangeLanguage(1053)"></a>. My question is: can we use java script function on custom aspx page ? As i know, on custom aspx page, only content Controls are allowed. any idea to slove this problem –  SPBeginer Dec 17 '12 at 12:54
    
@Mustafa646 is it? I thought there isn't any problem in using JavaScript in custom application pages.. Setting Up an Application Page for JavaScript –  Arsalan Adam Khatri Dec 17 '12 at 13:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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