I have a problem with initializing internal file.
Specifically https://www.detectadblock.com/
I can't initialize this ads.js file on my project.
var e=document.createElement('div');
e.id='punVTqCWOHsB';
e.style.display='none';
document.body.appendChild(e);
My web browser always failed with loaded script. Any suggestions how can I proceed?
Loading failed for the with source “127.0.0.1:8888/AdBlock/src/com/example/myproject/public/ads.js”." github.com/marosmamrak/AdBlock-1.git
You are giving the full path to the source files (in src/.../public), but that file will be copied with the rest of the GWT compiled sources, so it should be inside the adblock directory to match your .nocache.js file:
<script type="text/javascript" language="javascript" src="adblock/adblock.nocache.js"></script>
<script type="text/javascript" language="javascript" src="adblock/ads.js"></script>
Also please note that this does nothing at all, since the browser can't execute Java files directly:
<script src="/AdBlock/src/com/example/myproject/client/Flipper.java"></script>
Related
I'm using Turbolinks on my website. My website has many pages where each page has a unique JS file in addition to the "base" js file.
Every page has the following scripts in its head:
<head>
...
<script defer src="/js/manifest.js" data-turbolinks-track="reload"></script>
<script defer src="/js/vendor.js" data-turbolinks-track="reload"></script>
<script defer src="js/app.js" data-turbolinks-track="reload"></script>
...
</head>
Every page may include another JS file in its body:
<body>
...
<script src="/js/pages/page1/index.js"></script>
</body>
Now many pages may load the same js file in their body tag:
Page1:
<body>
...
<script src="/js/pages/page1/index.js"></script>
</body>
Page 2:
<body>
...
<script src="/js/pages/page1/index.js"></script>
</body>
Page 3:
<body>
...
<script src="/js/pages/page3/index.js"></script>
</body>
Note how Page 1 and Page 2 load the same js file.
In order to build those JS files I use Laravel Mix which uses Webpack to compile and bundle the JS files.
When navigating between pages, since the JS file is embedded in the <body> element, the JS file is being re-downloaded (from cache) and re-evaluated by the browser. One would expect that if page1/index.js content is: console.log('hey');, they would see hey printed in their console for every page that loads the page1/index.js page.
However, unfortunately it is not the case. It seems like the browser does re-downloads the JS file, but for some reason, its content is not being executed. I believe this is due to the transpiled file's content. Because we are using Webpack to bundle the files, the file's content always starts with the following script:
(window.webpackJsonp=window.webpackJsonp||[]).push(...
It looks like Webpack is managing the runtime scripts on its own in order to keep track of dependencies (and also "lazy" dependencies). Inspecting the window.webpackJsonp variable does indeed reveals 2 entries for the pages1/index.js file (the first entry is when the page was first loaded, the second one is when we navigated to another page that loaded that same file).
For some reason, Webpack decides not to re-run the script on subsequent page visits (using Turbolinks) which breaks the application.
Any ideas about what I can do in order to solve this are highly appreciated!
Purpose: To understand what web pages have imported a .js file that I have written.
Is there any way to inject a script into my .js file so that I can collect information about the sites ( at least domain name)?
e.g
an X Site, https://www.x-site.com, has this import on its HP.html where I have NO access to.
<script src="https://domain.co/common-files/js/startup.js"></script>
And I want this startup.js file to somehow notify me that the x-site.com has been benefiting from itself.
The first thought in my mind is that I can simply make GET requests inside that JS file, with a parameter to another HTML file that my server hosts.
What do you think the best practice for that would be?
PS: I have no access to the server hosting the JS file since the platform I use is a CMS where I can simply load the assets including the aforementioned JS file.
PS2: I have no access to the websites that use this JS file either.
A possible solution, where the code in the body tag could be in your startup.js:
<html>
<head>
<script
src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.js"></script>
<script src="https://domain.co/common-files/js/startup.js"></script>
</head>
<body>
<script language="javascript" type="text/javascript">
var scripts = document.getElementsByTagName("script");
for (var i = 0; i < scripts.length; i++) {
var src = scripts[i]['src'];
if (src && src.indexOf('https://domain.co/common-files/js/startup.js')>-1) {
// track.php is a empty js file
document.write('<script src="https://domain.co/track.php?siteUsingMyJs=');
document.write(window.location.href);
document.write('"><\/script>');
}
}
</script>
</body>
</html>
The simplest and most robust solution would be to configure your servers' access logs to track who is downloading your script file.
Look at this Apache documentation, for example. It outlines how to make custom conditional log files.
I was wondering about the syntax of running external .js files, when you do it normally you just do
<script src=http://www.example.com/javascript.js></script>
but when running code in chrome (through the url bar), where the syntax is:
javascript:javascriptcodegoeshere
The <script> tags aren't included, so how can you launch a js file through using that?
You have four options.
You can put the actual code in the <script> block.
<script>
javascriptcodegoeshere
</script>
You can save the code in a file and refer to it.
<script src="http://www.example.com/javascript.js"></script>
You can put it as a data URL.
<script src="data:text/javascript,javascriptcodegoesgere"></script>
You can put it in a link if you want the user to launch the code.
link
I'm using webform asp.net and C#. I linked the master page with javascript file like this
<script type="text/javascript" src="javascript/main.js"></script>
but when I'm going to inner pages inside folders.. I can't access the JavaScript file.. (404 error).I tried to solve the problem by using ResolveClientUrl but it's not work!
What's the problem?
but when I'm going to inner pages inside folders.. I can't access the JavaScript file
Since the page you're accessing is at a different level than your master page, you want to make the script path relative to the root of your application
<script type="text/javascript" src="/javascript/main.js"></script>
EDIT if that's not working, then I would keep the script tag as it is above, run it in Chrome with the developer tools / network tab open, and look at the exact address that shows up for the failed request. Then look closely at your application and see what's different / wrong.
You can do:
<script type="text/javascript" src="<%=Page.ResolveClientUrl("~/javascript/main.js") %>" />
Allows you to use ASP.NETs ~. If this doesn't work then the file doesn't exist in that directory.
Im attempting to utilize some custom script and css files within an asp page. In Visual Studio 2010 I am not getting any warnings or errors as to the status of these files, but when I attempt to run the page, and I open the javascript console I get the error:
Failed to load resource: the server responded with a status of 404 (Not Found)
Here's how I am attempting to load the files in my ascx file:
<script type="text/javascript" src="scripts/jquery.js"></script>
<script type="text/javascript" src="scripts/jquery.scripts.js"></script>
<script type="text/javascript" src="scripts/jquery.alerts.js"></script>
<link href="styles/jquery.alerts.css" rel="stylesheet"/>
Anyone know whats going on here, why the browser can't locate the files but visual studio can?
This happens when the location of the .aspx file is different to the location of the user control (ascx).
When the user control is rendered in the browser it will actually have the location of the .aspx and tries to make the reference from that point. Whereas in VS, it will try to make the reference to the file from the .ascx location.
Therefore, try referencing the files as if you were making the references from the .aspx file location. It shouldn't give you any error when rendering that page.
I've upvoted aleafonso's answer since he's correct. Now, to solve this issue, you can use the ResolveClientUrl method.
Something like this:
<script type="text/javascript" src='<%=ResolveClientUrl("scripts/jquery.js"%>'></script>