Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdate Javascript variables within external .js using PHP?
    primarykey
    data
    text
    <p>I am trying to create a Javascript file that I can reference from other domains that will allow the look and feel of a user's page to be changed.</p> <p>For example, The javascript file (www.mywebsite.com/123.js) would be referenced on www.userwebsite.com and could contain the below:</p> <pre><code>var thebody = document.getElementsByTagName('body')[0]; var newdiv = document.createElement('div'); var txtNode = document.createTextNode("Hello. This is a new node."); var divIdName = "mydiv"; var csslink = "http://www.anotherwebsite.com/style.css"; var newcss = document.createElement('link'); newcss.setAttribute('href',csslink); newcss.setAttribute('rel','stylesheet'); newcss.setAttribute('type','text/css'); newdiv.setAttribute('id',divIdName); newdiv.appendChild(txtNode); thebody.appendChild(newdiv); thebody.appendChild(newcss); </code></pre> <p>Which would insert a reference to a CSS file hosted on the user's website as well as add a new div to the DOM with the text node "Hello. This is a new node."</p> <p>I want the user to be able to login to a CMS (that I will build) so they can change the text that gets printed to the page without having to change the Javascript file that I give to them. The CMS would be hosted on my website.</p> <p>What is the best practice to do this? </p> <p>Obviously I could edit the javascript file remotely without the user needing to change anything - but is that the best method of updating the script?</p> <p>I was thinking of having an Ajax request in the javascript that retrieves output from a php file referencing a mysql database with the text the user wants to change to - however, the same origin policy means that isn't possible.</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload