简体   繁体   中英

How to call <script src> from a relative page

i have 2 pages:

HOME page with span element:

<span id="t1"></span>
<span id="t2"></span>

TEST page with js:

<script>
const data = {
"t1": 'value1',
"t2": 'value2',
}
Object.entries(data).forEach(([k, v]) => {
const span = document.getElementById(k);
if (span) span.innerHTML = v;
})
</script>

Due to technical limitation i can't create a .js file and call for it from HOME page and i need to use the same script from TEST page on HOME page without copy-pasting it.

Is it possible to call for the script without .js file from HOME page in a way similar to this:

HOME with a src path to TEST page script:

<span id="t1"></span>
<span id="t2"></span>

<script src="https://website.com/TEST"></script>

Tried but failed to have a result. Thanks in advance for your help

i have 2 pages:

HOME page with span element:

<span id="t1"></span>
<span id="t2"></span>

TEST page with js:

<script>
const data = {
"t1": 'value1',
"t2": 'value2',
}
Object.entries(data).forEach(([k, v]) => {
const span = document.getElementById(k);
if (span) span.innerHTML = v;
})
</script>

Due to technical limitation i can't create a .js file and call for it from HOME page and i need to use the same script from TEST page on HOME page without copy-pasting it.

Is it possible to call for the script without .js file from HOME page in a way similar to this:

HOME with a src path to TEST page script:

<span id="t1"></span>
<span id="t2"></span>

<script src="https://website.com/TEST"></script>

Tried but failed to have a result. Thanks in advance for your help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM