Skip to main content

Pass parameters to a Script tag - Get Parameters of Current Script Tag Src

Pass parameters to a Script tag - Get Parameters of Current Script Tag Src


Let This is Script Tag in your main html and you have to get the value of id parameter in script.js 
or
Get Parameters of Current Script Tag Src
or
Pass parameters to a Script tag

See an Example Below -
  
//Script Tag in Main HTML (i.e. index.html)
<script src="script.js?id=WqoYv89"></script>
  
Here is Content of script.js
  
//Content of Script.js
let params = new URL(document.currentScript.src);
params = params.searchParams;
console.log(params.get('id'));

  
Result on Console :- 

 WqoYv89


About UrlSearchParams :- https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/get

About Document.currentScript :- https://developer.mozilla.org/en-US/docs/Web/API/Document/currentScript


google tag manager,how to get a variable from another script javascript,script tag,how to access a variable from another html script,script tag api,where should the script tag go,how to access another script in javascript,how to access variables from another script,how to call method from another script,script tag in body vs head,transform php variable to javascript in laravel 5,laravel passing php var to jquery,url parameters,where should the script tag be placed in html,route parameters



Comments

Popular posts from this blog

Git Conflict Guide 🚀

What is a Git Conflict? A Git conflict occurs when two branches have changed the same part of a file, and Git cannot automatically merge the changes. When you attempt to merge or rebase branches, Git will pause the process and mark the conflicted files. Steps to Resolve a Git Conflict 1. Identify Conflicted Files When you encounter a conflict, Git will mark the conflicted files. You can see these files by running: git status Enter fullscreen mode Exit fullscreen mode 2. Open the Conflicted File Open the conflicted file(s) in your code editor. You'll see Git's conflict markers: <<<<<<< HEAD Your changes ======= Incoming changes >>>>>>> branch-name Enter fullscreen mode Exit fullscreen mode <<<<<<< HEAD marks the beginning of your changes. ======= separates your changes...

FamilyAlbum - Free Unlimited Storage - Share Family Photos and Videos - Auto-Organized Album

Website :- https://family-album.com Play Store :- https://play.google.com/store/apps/details?id=us.mitene Description from Play Store The best way to safely share and organize your family’s photos and videos. Unlimited storage, no ads, and it’s free! 3 Reasons to Start Your Album: 1) You’ll love it YOUR MEMORIES ON DISPLAY. Show off your photos and videos in a way that’s both beautiful and intuitive. Everything is automatically sorted by month, complete with your child’s age. Just swipe the screen to go back in time! UNLIMITED STORAGE. Back up all your memories for free. STREAMLINED SHARING. No more sharing the same photo with five different group chats. All your photos, all your videos, all your favorite people, all in one place. YOUR PRIVACY IS OUR PRIORITY. Your album is completely private. All content you upload to the app belongs to you, and it can only be viewed by you and the family and friends you invite. That also ...

Random Posts