HTML DOM Script src attribute
Examples
Get external URL script:
var x = document.getElementById("myScript").src
x The output is:
http://www.w3cschool.cc/jsref/demo_script_src.js
try it"
Definition and Usage
Sets or returns the value of the src attribute of the script src attribute.
src attribute specifies the URL of an external script file.
If you want to run the same JavaScript on the site of several pages, you should create an external JavaScript file, instead of repeating the same scripting. The extension .js script file to be saved, and then refer to it using the src attribute in <script> tag.
Note: The external script file can not contain <script> tag.
Note: The script is written correctly reference your external script file.
Browser Support
All major browsers support the src attribute.
grammar
Back src attribute:
scriptObject .src
Setting the src attribute:
scriptObject .src= URL
Property Value
值 | 描述 |
---|---|
URL | 外部脚本文件的 URL。 可能的值:
|
technical details
return value: | String that represents the URL of an external script file. Returns the complete URL, including the protocol (such as http: //). |
---|
related articles
HTML Reference Manual: HTML <Script> the src attribute