How to get site URL to populate in script, not PHP?
-
I have a custom theme that has a script function to change the default Twitter/FB share text. Since I have this on a multisite install, I can’t have a default URL, it needs to change depending on what site you’re on. How can I call the site URL here?
Here’s my code:
function twittershare( ){ var score = document.getElementById("answer_score").innerHTML; var grade = document.getElementById("answer_grade").innerHTML; var score_list = score.split("/"); url = "https://twitter.com/home?status=" + encodeURIComponent( "My score on Spark Trivia was " + score_list[0] + " out of " + score_list[1] + " and my grade? " + grade + "! See if you can beat me at https://www.sparktrivia.com/ @sparktrivia" ); window.open( url, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600'); }
Any instance of “https://www.sparktrivia.com/” needs to be changed.
Thanks!
- The topic ‘How to get site URL to populate in script, not PHP?’ is closed to new replies.