소스 검색

added urlQueryParameter helper function

Alexander Rose 6 년 전
부모
커밋
4257279026
1개의 변경된 파일12개의 추가작업 그리고 0개의 파일을 삭제
  1. 12 0
      src/mol-util/url-query.ts

+ 12 - 0
src/mol-util/url-query.ts

@@ -0,0 +1,12 @@
+/**
+ * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ *
+ * @author Alexander Rose <alexander.rose@weirdbyte.de>
+ */
+
+export function urlQueryParameter (id: string) {
+    if (typeof window === 'undefined') return undefined
+    const a = new RegExp(`${id}=([^&#=]*)`)
+    const m = a.exec(window.location.search)
+    return m ? decodeURIComponent(m[1]) : undefined
+}