By searching a bit, one could find this question about stopping chrome from loading a javascript file.
But this doesn't work for a script which is not linked, for example:
<!-- Some html here -->
<script id="script">
//Some script here
</script>
The script here is coded inside the html page and not linked from an external .js file. As you can see, I'm looking for a way to disable that and only that #script before it gets loaded.
Thanks in advance for your help.
Related
I am given this code which should display an embedded small coupon version of this page https://weedmaps.com/deals#/1118217:
<script type="text/javascript">var coupon_id = 17811;</script>
<script type="text/javascript">var coupon_type = "deliveries";</script>
<script type="text/javascript" src="https://weedmaps.com/embed/coupon.js"></script>
I do not know how to add the JavaScript to the HTML correctly. I have placed the following scripts in the head section. But I don't understand how to have the coupon generate in the div I want it to. I have tried calling the JavaScript function, but I've never worked with JavaScript before. Could someone please help me embed this coupon.
I've taken a look at your script and first of all: it definitely should be placed inside the document and not into the <head> section because coupon.js is writing out html at the placement of the coupon.js script import.
In theory you just need to place the script and it should work but there are some problems:
You need to execute it on a web server - when running as a plain html file the script just tries to find the libraries in your file system which does not work.
It still would not work because it would still try to find some resources at your web-server. In mycase it the script tried to load http://localhost:63342/restpoints/deliveries/17811/deal which will not work
To prove 2. just try https://weedmaps.com/restpoints/deliveries/17811/deal with the correct domain. Then you are receiving correct JSON which is used to fill the coupon pane.
=> Consequently the script you were given has problems if it should be executable from domains different from "weedmaps.com"
Javascript can be between head tag but it advisable to put it below before the body closing tag, to allow your page contents loads first before loading javascript. Just import your javascript. and call out. Hope this was helpful.
<!DOCTYPE html>
<html>
<head>
</head>
var coupon_id = 17811;
The JS indicates it is looking for an element with an id of #weedCouponPane. Do you have this in your html? i.e.
<div id="weedCouponPane"></div>
I'm trying to put a code snippet into an external .js. Works fine as is inside the page file but stops working if I pull out the script to an external file. I'm thinking it's a variable issue but I'm not entirely clear how to fix that. Little help. Thanks.
Here's the current working internal code:
<script src="scripts/jquery-1.12.4.min.js"></script>
<script src="scripts/jquery.flurry.js"></script>
<script>
$(document).ready(function(){
$("body").flurry({height:300,frequency:98,speed:4321,small:11,large:61,wind:40,windVariance:98,rotation:272,rotationVariance:98,
startOpacity:1,endOpacity:0,opacityEasing:"cubic-bezier(1,.3,.6,.74)",blur:true,overflow:"hidden",zIndex:9999});
$(".toggle-snow").on("click",function(event){
event.preventDefault();
try{
$("body").flurry("destroy");}
catch(err){
$("body").flurry();}
});
});
</script>
When I pull that third script into a fall.js file, the code stops working. Is there something that I need to add to the external script or the internal file?
--
Ah! Silly me. Needed to just remove the open / closing tag in the fall.js file.
Why do you have the "?>" and inside the fall.js remove the opening and closing tags.
Keep references to the other external files in the html
Before referring to fall.js
How are you trying to register the script?
<script src="scripts/jquery-1.12.4.min.js"></script>
<script src="scripts/jquery.flurry.js"></script>
<script src="fall.js"></script>
This should be enough to make the script work, as long as the fall.js file is served in the /fall.js route
I am using a simple plugin from http://www.highcharts.com/demo/pie-basic which has a javascript file stored in view options. I am using this file in my index.html code as <script src="js/pie1.js"></script> inside <body> tag where pie1 is a javascript file stored in js folder. When i run my html page nothing happens.
can anyone help me where I am getting wrong? I am new to using plugins so please bear with me and correct me if anything is wrong.
Most likely you have this situation because javascript start running the plugin before your html is ready.
Place <script src="js/pie1.js"></script> just before closing tag </body>
I have used below code to append link tag in head section. It is having below behavior
1. I am able to see the attached link tag in firebug but not in page souce
2. my head section belongs to a different jsp file
Can i get some tips on this?
Below is the script I have used in body section
<script type="text/javascript">
var appendHTML= "<link rel='next' href='http://test.com'/>";
$('head').append(appendHTML);
</script>
Thanks,
Abhishek
You are not alone witch such kind of task on SO. Try to find around and you will see same themes - How to load up CSS files using Javascript?
I'm currently having a weird problem.
I'm using JqueryUI tabs, and am loading php pages with each tabs. This works well for me, but what I am trying to do, is loading another php page from within one of those tabs with the html "a" tag. For some reason, it doesn't work when I place the click function in a already linked javascript file, but works when I place the code in a script tag directly in the html file.
Here is the function:
$(function(){
$('a.commandsRecep').on('click',function(e){
e.preventDefault();
window.open(this.href,'','width=700,height=700');
});
})
I know that loading pages from within a tab is done by Ajax and am wondering if that's what causing me problems.
The link is inside a table :
<td><a class="commandsRecep" href="./Ben_test/page_principale.php">Réception des commandes</a></td>
What is the order of includes?
Make sure that jquery is included before javascript file.
The order should be like :
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="yourScript.js"></script>
Found it!
After a while, I got to the same type of error.
What I had to do was separate my script in two parts, one that required jqueryUI and one that didn't.
That way, in the html files where I don't import jqueryUI, I only import the one that doesn't require it.
Looks like having jquery that required jqueryUI without having imported jqueryUI was stopping the script from executing.