Rodomi pranešimai su žymėmis JavaScript. Rodyti visus pranešimus
Rodomi pranešimai su žymėmis JavaScript. Rodyti visus pranešimus

2014 m. liepos 29 d., antradienis

JavaScript: console

Vietoje alert galima naudoti console.

if (window.console) console.log

IE - veikia su developer tools
Kitose naršyklėse veikia natūraliai

console:
- error
- log
- warn

2014 m. balandžio 7 d., pirmadienis

JavaScript: how to read var from URL

 function getUrlVars() {
            var vars = [], hash;
            var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
            for (var i = 0; i < hashes.length; i++) {
                hash = hashes[i].split('=');
                vars.push(hash[0]);
                vars[hash[0]] = hash[1];
            }
            return vars;
        }

var dm = getUrlVars()["GID"];

2014 m. sausio 21 d., antradienis

JQuery: unload event, JavaScript: onbeforeunload event

Problema: pagauti įvykį, kad su window.open atidarytas langas uždaromas ne mygtuko paspaudimu, o pasirinkus dešiniajame viršutiniame kampe esantį mygtuką.

Sprendimas: naudoti unload event - lango užsarymo metu

 $(window).unload(function () {
            alert("Handler for .unload() called.");
        });



Arba naudoti onbeforeunload, prieš uždarant langą:

window.onbeforeunload = function () {
            return 'You have unsaved changes!';
        }

http://api.jquery.com/unload/ - JQuery įvykis

http://help.dottoro.com/ljhtbtum.php - onbeforeunload IE įvykis



http://help.dottoro.com/ljfvvdnm.php - visi įvykiai

2013 m. spalio 11 d., penktadienis

Fiunction find difference betwen two dates

 function calcDiff(date1, date2) {
            //Get 1 day in milliseconds
            var one_day = 1000 * 60 * 60 * 24;

            // Convert both dates to milliseconds
            var date1_ms = date1.getTime();
            var date2_ms = date2.getTime();

            // Calculate the difference in milliseconds
            var difference_ms = date2_ms - date1_ms;
            //take out milliseconds
            difference_ms = difference_ms / 1000;
            var seconds = Math.floor(difference_ms % 60);
            difference_ms = difference_ms / 60;
            var minutes = Math.floor(difference_ms % 60);
            difference_ms = difference_ms / 60;
            var hours = Math.floor(difference_ms % 24);
            var days = Math.floor(difference_ms / 24);

            return minutes + ' minutes, and ' + seconds + ' seconds';
        };

2013 m. rugsėjo 25 d., trečiadienis

AsyncPostBackTrigger nenaudoti su Response.Write

Dideliuose projektuose, kur daug JavaScript bibliotekų ir UpdatePanel, gaunama "mistinė" klaida dėl to, kad vb kode buvo panaudotas Response.Write

2013 m. rugsėjo 17 d., antradienis

Disable Browser Back Button Using JavaScript ASP.NET

Sprendimas:

JavaScript:

function disableBackButton()
{
window.history.forward();
}
setTimeout("disableBackButton()", 0);
< body   onunload=" disableBackButton() " >

http://www.codeproject.com/Questions/89384/Disable-Browser-Back-Button-Using-Javascript-ASP-N.aspx

2013 m. rugsėjo 12 d., ketvirtadienis

Datos formatas pagal lokalią kalbą JavaScript ir ASP.NET

Problema: atnaujinant duomenis su JavaScript, dažnai reikia išlaikyti datos formatą pagal lokalią kalbą.

Sprendimas:

var d = new Date(MeetDate).localeFormat("d"); - JavaScript

< % #  Eval("MeetDate", " { 0 : d } ") % > - ASP.NET

Daugiau: http://www.asp.net/AJAX/Documentation/Live/ClientReference/Global/JavascriptTypeExtensions/DateTypeExt/default.aspx

In Chapter 6: ASP.NET AJAX Localization, on page 289, we have a tip on Data Format Strings. It states that “the data format strings available for the Date and Number types in JavaScript are the same as those that are available in .NET for the DateTime and Double types.” This is incorrect.
The format strings that are allowed for Number types are the following:
  • c or C: Currency
  • p or P: Percentage
  • d or D“: Decimal (# number of digits)
  • n or N“: Numeric (# number of digits after decimal)
- e, f, g, r, x, and custom format strings are not supported
The standard format strings that are allowed for the Date type are the following:
  • d: Short date pattern
  • D: Long date pattern
  • t: Short time pattern
  • T: Long time pattern
  • F: Full date/time pattern (long time)
  • m or M: Month day pattern
  • s: Sortable date/time pattern
  • y or Y: Year month pattern
- the standard format strings: f, F, g, G, O, o, R, r, u, U are not supported. However, custom format strings that use the “mmm”, “yyyy”, “hh”, etc. formats are supported. You can build your own date format string.

http://seejoelprogram.wordpress.com/2008/08/07/supported-number-and-datetime-format-strings-in-aspnet-ajax/




Kaip iš DateTime gauti datos formatą JavaScript'e:

DateAdded: (new Date(parseFloat(result.d[i].auditdate.slice(6, 19)))).localeFormat("d")

čia 6,19 iš DateTime formato nuima pradžią ir pabaigą.

2013 m. rugpjūčio 23 d., penktadienis

Understanding RegisterClientScriptBlock and RegisterStartupScript

RegisterClientScriptBlock - įterpia javascript tekstą prieš formuojant HTML(nenaudojamas dirbant su UpdatePanel, nes scriptų neužregistruoja).

RegisterStartupScript - įterpia javascript tekstą jau suformavus HTML elementus (naudojama inicializacijai ir dirbant su UpdatePanel).

Partial Class Default2
    Inherits System.Web.UI.Page

    Protected Sub Page_PreRender(sender As Object, e As EventArgs) Handles Me.PreRender
        Dim sScript As String = "" &
            "function checkBox() {" &
            "   if (document.getElementById('" + TextBox1.ClientID + "').value != 'OK') {alert('Wrong'); return false} else {return true};" &
            "};"
        ScriptManager.RegisterClientScriptBlock(Me, Me.GetType, "tt", sScript, True)

        Button1.Attributes.Add("onclick", "return checkBox();") - užregistruoja, kada turi būti iškviečiama javascript funkcija

        ScriptManager.RegisterStartupScript(Me, Me.GetType(), "ttt", "document.getElementById('" + TextBox1.ClientID + "').value = '" & Now().ToString() & "';", True)
    End Sub

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Literal1.Text = Now()
    End Sub
End Class

Pagal tokį kodą, HTML suformuojamas taip:


2013 m. vasario 3 d., sekmadienis

JavaScript: onFocus, onBlur

onfocus priešingas onblur

$(document).ready(function () {
            $('#txtHours').val("Hours");
        });


function onBlur() {
            if ($('#txtHours').val() == "") {
                $('#txtHours').val("Hours");
            };
        };


function onFocus() {
            if ($('#txtHours').val() == "Hours") {
                $('#txtHours').val("");
            };
        };


<asp:TextBox ID="txtHours" runat="server" Width="70px" AutoCompleteType="Disabled" Visible="false" onfocus="onFocus();" onblur="onBlur();"></asp:TextBox>

2013 m. sausio 27 d., sekmadienis

Windows Media Files to Web page

1. Naudojame object.

Playlist.aspx?ID=142 - failas, kuriame sudėtas video sąrašas

< object id="Player" width="900" height="700" classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" standby="Loading Windows Media Player components..." type="application/x-mplayer2" >
< param name="FileName" value="Playlist.aspx?ID=142" >
< param name="autostart" value="true" >
</ object >

2. ASX failo struktūra, sudaranti video sąrašą:

< asx version="3.0" >


< TITLE > Playlist </ TITLE >

< ENTRY >

< TITLE >pavadinimas< /TITLE >

< REF HREF=http://serveris/pavadinimas.wmv />

</ ENTRY >

< ENTRY >

< TITLE >naudojami-komponentai</ TITLE >

< REF HREF=http://serveris/pavadinimas2.wmv />

</ ENTRY >
</ asx >

3. Javascript  

SetCurrentEntry - pakeičia dabar grojantį video į nurodytą
getCurrentEntry - rodo dabar grojančio video numerį  

function managePlaylist(orderID) {
if (document.getElementById('Player').getCurrentEntry() == 1) {

try {

document.getElementById('Player').contentDocument.Play();

} catch (err) { }
}


try {
document.getElementById('Player').contentDocument.SetCurrentEntry(orderID);
}
catch (err) {
}

}


 function StartMeUp() {
            document.getElementById('Player').contentDocument.autostart = "true";
            document.getElementById('Player').contentDocument.Enabled = "true";
            document.getElementById('Player').contentDocument.Play();
 }

 function ShutMeDown() {
     document.getElementById('Player').contentDocument.Enabled = "false";
 }

Daugiau:
http://msdn.microsoft.com/en-us/library/ms983653.aspx
http://www.microsoft.com/windows/windowsmedia/howto/articles/adsolutions2.aspx#creatingtheannouncementfile


Dėl mp4 formato palaikymo Windows Media Player'yje: pageidaujamas formatas yra .wmv, nors Windows Media Player 12 palaiko ir mp4 formatą.


Media Player 12 yra tik nuo Windows 7, Windows XP - palaiko tik Windows Media Player 11.

http://support.microsoft.com/kb/316992 - Windows Media Player formatų palaikymas

2013 m. sausio 10 d., ketvirtadienis

JavaScript IE vs JavaScript Chrome

IE works:

function validateMax2500Len(source, args) {


var x = (document.getElementById("txtDesc").value);

var l = document.getElementById("txtDesc").lastChild.length;

document.getElementById("lblLength").innerText = l;

if (x != "") {

if (l <= 100) { args.IsValid = true; }

else { args.IsValid = false; }

};

};   Chrome works:   function validateMax2500Len(source, args) {

var x = (document.getElementById("txtDesc").value);

var l = document.getElementById("txtDesc").value.length;

document.getElementById("lblLength").innerText = l;

if (x != "") {

if (l <= 100) { args.IsValid = true; }

else { args.IsValid = false; }

};

};

2011 m. balandžio 18 d., pirmadienis

JavaScript DOM API

HTML puslapio dinaminio modifikavimo galimybės su DOM API http://www.howtocreate.co.uk/tutorials/javascript/dombasics

Labai gražus dinaminio pridėjimo-išmetimo pavyzdys - validuojant užpildytą formą, pranešimus būtent pridėti-ištrinti, o ne kaip dažnai naudojama - rodyti-slepti informacinius elementus.

2011 m. balandžio 15 d., penktadienis

YouTube JavaScript Player

Dažnai reikia atvaizduoti YouTube video su tik Jūsų puslapiui reikalinga išvaizda. Tokiu atveju galima naudoti JavaScript. Daugiau yra funkcijų, pavydžių yra čia: http://code.google.com/intl/lt/apis/youtube/js_api_reference.html

Pavyzdys, kaip galima koreguoti, naudoti YouTube įrašus savo svetainėje, pavyzdžiui, paleisti, sustabdyti, rodyti tik nuo tam tikros minutės, yra čia: http://code.google.com/apis/youtube/chromeless_example_1.html

Įdomus sprendimas YouTube video vaizduoti popup'e: http://web3o.blogspot.com/2009/06/easy-to-use-popup-youtube-player-using.html

2010 m. spalio 13 d., trečiadienis