Question

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 ?

Was it helpful?

Solution

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top