File tree Expand file tree Collapse file tree 3 files changed +47
-1
lines changed Expand file tree Collapse file tree 3 files changed +47
-1
lines changed Original file line number Diff line number Diff line change 1
1
# Query-passer
2
- Passing query parameters from the URL to HREF links
2
+
3
+ Query-passer is a simple script that passes all query strings from the current URL to all existing ` <a> ` tags in a page.
4
+
5
+ The script helps you to keep the query strings across all pages in your website.
6
+
7
+ Hashtag anchors (` <a href="#info"> ` ) will be placed after the query strings (` <a href="?cid=1#info"> ` ).
Original file line number Diff line number Diff line change
1
+ $ ( document ) . ready ( function ( ) {
2
+ $ ( function ( ) {
3
+ var href ;
4
+ $ ( 'a' ) . each ( function ( ) {
5
+ href = $ ( this ) . attr ( 'href' ) ;
6
+ if ( href !== "undefined" && href != null && href && href . length > 1 ) {
7
+ if ( href !== 'undefined' || href . substr ( 0 ) != '' || href !== null ) {
8
+ if ( href . substr ( 0 , 1 ) == '#' ) {
9
+ $ ( this ) . attr ( 'href' , location . search + href ) ;
10
+ } else if ( href . indexOf ( '#' ) > 0 ) {
11
+ href = href . split ( '#' ) ;
12
+ $ ( this ) . attr ( 'href' , href [ 0 ] + location . search + '#' + href [ 1 ] ) ;
13
+ } else {
14
+ href += location . search ;
15
+ $ ( this ) . attr ( 'href' , href ) ;
16
+ }
17
+ }
18
+ }
19
+ } ) ;
20
+ } ) ;
21
+ } ) ;
Original file line number Diff line number Diff line change
1
+ ( function ( ) {
2
+ var href ;
3
+ document . querySelectorAll ( 'a' ) . forEach ( function ( ele ) {
4
+ href = ele . getAttribute ( 'href' ) ;
5
+ if ( href !== "undefined" && href != null && href && href . length > 1 ) {
6
+ if ( href !== 'undefined' || href . substr ( 0 ) != '' || href !== null ) {
7
+ if ( href . substr ( 0 , 1 ) == '#' ) {
8
+ ele . setAttribute ( 'href' , location . search + href ) ;
9
+ } else if ( href . indexOf ( '#' ) > 0 ) {
10
+ href = href . split ( '#' ) ;
11
+ href [ 0 ] + location . search + '#' + href [ 1 ]
12
+ ele . setAttribute ( 'href' , href [ 0 ] + location . search + '#' + href [ 1 ] ) ;
13
+ } else {
14
+ href += location . search ;
15
+ ele . setAttribute ( 'href' , href ) ;
16
+ }
17
+ }
18
+ }
19
+ } ) ;
20
+ } ) ( ) ;
You can’t perform that action at this time.
0 commit comments