Posts
Showing posts with the label Jquery
Click event count on page using jquery
- Get link
- X
- Other Apps
$ ( document ). click ( function ( e ) { if ( e . currentTarget . activeElement . attributes [ 0 ]) { var idClicked = e . currentTarget . activeElement . attributes [ 0 ]. value ; } if ( e . currentTarget . activeElement . attributes [ 1 ]) { var idClicked1 = e . currentTarget . activeElement . attributes [ 1 ]. value ; } if ( idClicked == 'loginbutton' || idClicked1 == 'loginModal' || idClicked1 == 'close' ) { } else { var auth_token = $ . session . get ( "auth_token" ); var user_id = $ . session . get ( "user_id" ); var pathname = window . location . pathname ; var patharray = pathname . split ( "/" ); var pageurl = patharray [ patharray . length - 1 ]; if (!( auth_token && user_id ) && pageurl != "re
Get URL parameters using jQuery
- Get link
- X
- Other Apps
jQuery code snippet to get the dynamic variables stored in the url as parameters and store them as JavaScript variables ready for use with your scripts. Used differently to Hash Url’s as the world turns to dynamic web apps. Thus things like Decoding URL Strings will be ever-popular for years to come. $ . urlParam = function ( name ) { var results = new RegExp ( '[\?&]' + name + '=([^&#]*)' ) . exec ( window . location . href ) ; return results [ 1 ] || 0 ; } // example.com?param1=name¶m2=&id=6 $ . urlParam ( 'param1' ) ; // name $ . urlParam ( 'id' ) ; // 6 $ . urlParam ( 'param2' ) ; // null //example params with spaces http : / / www . jquery4u . com ? city = Gold Coast console . log ( $ . urlParam ( 'city' ) ) ; //output: Gold%20Coast console . log ( decodeURIComponent ( $ . urlParam ( 'city' ) ) ) ; //output: Gold Coast This could be used for example to