I thought it`s as simple as HTML to include multiple external scripts in SVG.
But false ...
<script type="text/javascript" xlink:href="js/First_Script.js"/>
<script type="text/javascript" xlink:href="js/Second_Script.js"/>
doing like this, none of the scripts will work.
It's not possible for me to include the content of the second script into the first, because the first will be automatically rewritten by a function in an external program.
any suggestion?
Cheers ... Peedy
use <script></script> instead of <script/>. this is a known issue with script tag and svg.
Related
My problem is that I wrote a lot of code inside <script type="text/javascript"></script> tags and most of this code is Jquery code and initially this works because it was referenced to a remote source:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
But the thing is that it can't depend on internet, so I need all this code working locally and I can't adjust all those lines to $this->registerJs(""); It's just endless work.
So how can I make all this code inside <script></script> tags works locally with Jquery?
Thanks in advance.
You can put your script into a js file inside your project, and register it like follows:
$this->registerJsFile('#web/js/myCustomJs.js', [
'depends' => [\yii\web\JqueryAsset::className()]
]);
So you don't need to juggle with single and double quotes trying to make it work with $this->registerJs("");.
Note: on the example code depends makes it so your js file loads after Jquery.
we can link a CSS file in HTML file. But how can I link JavaScript file in an html file?
Suppose if we link a CSS file we write
Like that how can I link a JavaScript file?
Use a <script> tag.
<script src="/some/server/resource.js"></script>
Note that the type attribute is no longer necessary. You used to write it as:
<script type="text/javascript" src="/a/b/c.js"></script>
Bear in mind that where you put the <script> tag can impact how the JavaScript behaves as it can block the DOM while loading if added to the <head>. The differences about what placement changes what is an entirely different question.
you can link a javascript file in a HTML document using the script tag.
Here is an example:
<script src="myscripts.js"></script>
Here is some more information about this: http://www.w3schools.com/tags/att_script_src.asp
You can also write javascript inside script tags like normal.
Add a <script src="url_to_your_script.js"></script> tag to your html file, preferably in the head tag.
For more information, visit https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script
<script src="your_file_name.js"></script>
Add this code at the end of your body tag.
Happy Coding:)
This seems like a rather dumb question to ask but I would like to resolve this quickly and start working.I have a folder in which my html resides and I have the javascript files in a seperate folder called js.I have tried to add the script like this:
<script type="text/javascript" src="js/gmaps.js">
and I have also tried like this:
<script type="text/javascript" src="./js/gmaps.js">
I have even tried like this:
<script type="text/javascript" src="/js/gmaps.js">
As far as I understand either of the first two should work:
/ root folder
./ current folder
../one folder up
The paths of the files are
/home/anr/Desktop/maps/server/client/js/gmaps.js
/home/anr/Desktop/maps/server/client/google_maps.html
UPDATE:
The js file has window.onload and it also creates another script tag programmatically and adds it to the dom,after moving to the external script file I find that the map does not load
Looks like you just need to close your script tag with a on the first example, which should work.
Be sure that you are closing your tag as well. Once you have the correct relative path, your syntax should be:
<script type="text/javascript" src="relative_path_here"></script>
The following link could be helpful for setting the relative path in HTML:
Basic HTML - how to set relative path to current folder?
Try this,
<script type="text/javascript" src="js/gmaps.js"></script>
The script tag should be closed
<script type="text/javascript" src="js/gmaps.js"></script> Tag should be closed
I also had a similar problem but not with the path. My problem is the encoding of the html file in my demo, change encoding to ASNI to fix problem.
I include the jquery external js file with the command:
<script type='text/javascript' src='js/jquery-1.11.0.js' ></script>
I will call it again in the same page a little bit below (this is because I am including this with php classes to make sure it is loaded before going on). So in the page, I will have 2 times the line at different places:
<script type='text/javascript' src='js/jquery-1.11.0.js' ></script>
I want to know if this will create problems in my page and if the script jquery will be loaded 2 times which would be inneficient.
Thanks,
John.
This will create issues for any plugin that is included between those two inclusion.. For example if you have :
<script type='text/javascript' src='js/jquery-1.11.0.js' ></script>
<script type='text/javascript' src='js/jquery-plugin.js' ></script>
<script type='text/javascript' src='js/jquery-1.11.0.js' ></script>
jquery-plugin.js will be overwritten and it will not work.
It will be included twice. There is no need to do it. If you absolutely must write the include tag in two places do it second time conditionally. Code below will include jQuery only if it is not included yet.
<script>
window.jQuery || document.write('<script src="js/jquery-1.11.0.js"><\/script>')
</script>
It should be fine, especially in modern browsers, but it is a little bit strange to do this.
If at any point you load jQuery plugins after the first script tag, these will no longer work because jQuery/$ has been re-initialised.
I can't think of any reason you would need to load this twice, though - are you sure you need to? Your best bet is to put the script tag at the bottom of the page, before closing the <body> tag.
Depending on the library, including it more than once could have undesired effects.
Think of it like this, if you have a script that binds a click event to a button, and you include that script twice, those actions will be ran twice when the button is clicked.
You could write a simple function that you call to load a script and have it keep track of files that have already been loaded. Or, I'm sure you could probably use a pre-existing JS loader such as LabJS and modify it.
Reference: What is the danger in including the same JavaScript library twice
I have a webpage with mostly basic HTML on it. There is one section where I load an RSS feed using JavaScript pulling from an external source (url). The problem is that my page will load everything up until that script, wait for the script to load (sometimes up to a few seconds), then load the rest of the page.
How can I force it to load the script after it has rendered the entire page first?
My code is something like this:
<html>
<more html>
<script language="JavaScript" src="http://..." type="text/javascript"></script>
<more html>
...
Two options:
Put your script block at the end of the page. This is good practice anyways due to the fact that your page strucutre will load before the script that is intended to manipulate it. Because the user generally notices the page loading but not the script, this gives the appearance of a faster load overall.
Include the defer attribute in the opening script tag. Note that defer can only be used on external script files (those with an src attribute). See https://developer.mozilla.org/en-US/docs/HTML/Element/script.
Add the defer attribute to the script tag in the head also works
<script language="JavaScript" src="http://..." type="text/javascript" defer></script>
Reference link: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-defer
A pretty reliable way to make a script load after pageload is to write out the script include itself in javascript.
var theScript = document.createElement("script");
theScript.setAttribute("type","text/javascript");
theScript.setAttribute("src","//www.mysite.com/script.js");
document.getElementsByTagName("head")[0].appendChild(theScript);
You could try wrapping the function that calls the feed in
jQuery(window).load(function(){
//embed RSS feed
});
forcing it to load last.
Move your script tag to the end and it will load after everything else. For example:
<html>
<more html>
<more html>
<script language="JavaScript" src="http://..." type="text/javascript"></script>
</html