I am having issues with an external JS file - javascript

I am new to JavaScript. I have an external js file linked to a page, but its just not working. I don't know the line i went wrong in the js file. Help, please
function show_alert()
{
alert("Hello! I am an alert box!");
}
<input type="button" onclick="show_alert()" value="Show alert box" />
This is the code i used to link the file
<head>
<script type="text/javascript"
src="js\popup.js"></script>
</head>

First check the console in the Developer tools of your browser for any errors ( use F12 or Ctrl + Shift + I to open dev tools). If there's no error in the console, then check if the file path you stated is present in the directory you are.

Related

How to catch error on window.location.href ("url") in IE on html

URL is opening when u enter manually on address bar of IE. But while we add the url into javascript with html file. when opening html file is not working. shows some bootstrap error. On other hand, this html file is opening without error on Edge,Chrome & firefox browsers. can anyone face this same problem?
Webbrowser control on winforms using C#.
Code is here:-
<html>
<body>
<script type="text/javascript">
function Redirect() {
window.location.href = "https://www.dream11.com";
}
<input type='submit` value='purchase' onclick="Redirect();" />
</body>
</html>
output as URL needs to loaded without any errors. 'C#,Javascript'people provide me idea to stop the solution
Try using input type button rather than input type submit. It will work please try this.

Chrome extension form input text is blank on submit

I'm trying to build a chrome extension that downloads a bunch of items from links, the main logic is in my download.js file and I want to be able to specify in which downloads subfolder I'd like to bundle them all but the value of the input field seems to be empty. Here's my code so far
popup.html
<!doctype html>
<html>
<head>
<title>Download CVs</title>
<script src="popup.js"></script>
</head>
<body>
<form id="folderForm">
Subdir of downloads:
<input type="text" id="folder">
<input type="submit" id="download" value="Download CVs">
</form>
</body>
</html>
popup.js
function bundleItems() {
chrome.tabs.executeScript({
file: 'download.js'
});
}
document.addEventListener('DOMContentLoaded', function() {
var downloadButton = document.getElementById('download');
downloadButton.addEventListener('click', bundleItems);
});
chrome.extension.onRequest.addListener(function(logs) {
var folder = document.getElementById('folder').value;
logs.map(function(log) {
chrome.downloads.download({
url: log.attachment.link,
filename: folder + '/' + log.attachment.filename
});
});
});
I'm sending information from download.js to popup.js and everything works if I try to download it in downloads, so I feel posting my download.js file will be useless. However, if I try to display the folder variable, it's empty. I've searched for lots of other posts on the same issue and none of the solutions seem to work for me.
You cannot submit to a Chrome extension page. There is no web server to process your POST request in this case. Doing so simply reloads the document (clearing your value from the form).
You need to prevent submitting instead, by specifying type="button" for your button.
I would add preventDefault() on submit button.
https://developer.mozilla.org/en/docs/Web/API/Event/preventDefault

How to run .exe file or .bat file based on button click event using Javascript

In my current project, I would like to run .bat or .exe file using button click event using JavaScript. The content of batch file is as shown below:
start "S:\" TemperatureSensor.exe
which start TemperatureSensor.exe file when TemperatureSensor button is clicked.
Code for HTML page is shown below:
<!DOCTYPE html>
<html>
<body>
<p>Click the button to make a BUTTON element with text.</p>
<button onclick="window.open('file:///S:/Test.bat')">Temperature Sensor</button>
</body>
</html>
When I clicked on Temperature Sensor button, it should run Test.bat file but it just display following in new page:
Am I missing ?? Is it possible to run .exe file using button click event??
Updated:
Code for HTML page is shown below:
<!DOCTYPE html>
<html>
<body>
<p>Click the button to make a BUTTON element with text.</p>
<button onclick="myFunction()">Temperature Sensor</button>
<script>
function myFunction() {
var oShell = new ActiveXObject("Shell.Application");
var commandtoRun = "C:\\TemperatureSensor.exe";
if (inputparms != "") {
var commandParms = document.Form1.filename.value;
}
// Invoke the execute method.
oShell.ShellExecute(commandtoRun, commandParms, "", "open", "1");
}
</script>
</body>
</html>
When I clicked on Temperature Sensor button it displays error: Uncaught ReferenceError: ActiveXObject is not defined.
Just save this code as RunExe.hta and not RunExe.html and executes it by double click on it !
EDIT : REMARK about (HTA) (HTML Application)
HTML Application (HTA) is a Microsoft Windows program whose source code consists of HTML, Dynamic HTML, and one or more scripting languages supported by Internet Explorer, such as VBScript or JScript.
The HTML is used to generate the user interface, and the scripting language is used for the program logic.
A HTA executes without the constraints of the internet browser security model; in fact, it executes as a "fully trusted" application.
further reading about HTA HTML Application
<html>
<head>
<title>Run Exe or Bat files from HTA by Hackoo</title>
<HTA:APPLICATION
APPLICATIONNAME="Run Exe or Bat files from HTA by Hackoo"
ID="MyHTMLapplication"
VERSION="1.0"/>
</head>
<script>
function RunExe(){
var shell = new ActiveXObject("WScript.Shell");
var path = '"S:/Test.bat"';
shell.run(path,1,false);
}
</script>
<input style="width: 170px; height:23px; color: white; background-color: #203040;
font-family:Book Antiqua;" type="button" Value="Temperature Sensor" onClick="RunExe();"
</html>
If you're using firefox you could use this addon to open batch or exe files.
Exe and batch files aren't opening in browser by default becaue of security restrictions.
In a later version of the addon there will be an enable preference for exe-files and these files will be disabled by default.
But at the moment you can create links like test and launch the file with a click.

letter in quotes appearing just after body tag

We've just launched our new Magento site and the letter 'c' is appearing in quotes immediately after the tag. It's not showing up before on my local machine or on our QA site, I've checked the template files and it is not there either. I'm almost certain it can not be a code issue as we have the same code running locally and on our QA site under version control with GIT.
We've cleared the cache and I've tried checking to see if JavaScript was inserting it with the chrome dev tools but could find nothing.
Strangely, the 'c' is not in the view source document but I can see it with the chrome inspector.
I also don't think it can be coming from Magento CMS Pages/Blocks as it loading immediately after the tag.
thanks for the link. after reviewing the page source, you have an extra c character in the header area:
<!-- END GOOGLE ANALYTICS CODE -->
c<script type="text/javascript">//<![CDATA[
var Translator = new Translate([]);
//]]></script>
Notice that c before the script tag?
Just in support to Benny Lin's very helpful answer.
What was happening was we had our Google Analytics code loading from a template file which contained the stray letter 'c'. We could see this on our local machines as this templates was disabled in the Magento admin settings, but not on production.
This issue seems to demonstrate that when a stray letter appears within the <body> tags on your dev tools inspector and not the view source page it may be because it is in the <head> section. The browser seems to push all poorly formatted html from the <head> section into the <body> section when rendering.
For example if you open the below html in the chrome browser you will see what I mean:
<!DOCTYPE html>
<html>
<head>
c<title>Title of the document in head</title>
<script type="text/javascript">
var test = "test";
</script>
</head>
<body>
The body of the document......
</body>
</html>
Also while we were searching for the stray letter, we were ably to remove it with the below JavaScript that targets the offending XML node in the DOM with an XPath expression and removes that node only.
<script type="text/javascript">
function _x(STR_XPATH) {
var xresult = document.evaluate(STR_XPATH, document, null, XPathResult.ANY_TYPE, null);
var xnodes = [];
var xres;
while (xres = xresult.iterateNext()) {
xnodes.push(xres);
}
return xnodes;
}
jQuery(_x('//html/body/text()[contains(.,"c")]')).remove();
</script>

SERIALITY() plugin installation on firefox or chrome

Please help me to understand how to install the Seriality Plugin (www.zambetti.com/projects/seriality/‎) in Chrome or Firefox.
I want to read from a COM Port on the client side of a web page.
Take a look at the Google code site, this site contains the DMG file you can use to install the Seriality.plugin file.
https://code.google.com/p/seriality/
You can also see the sample source on the site that shows the javascript to use the plugin, below is a snippet shown on the site that prints "Hello World" to the first port seen on the system at a baudrate of 9600 when this HTML file is loaded.
<html>
<head>
<script type="text/javascript">
function setup()
{
var serial = (document.getElementById("seriality")).Seriality();
serial.begin(serial.ports[0], 9600);
serial.write("Hello World");
}
</script>
</head>
<body onload="setup();">
<object type="application/Seriality" id="seriality" width="0" height="0"></object>
</body>
</html>

Categories

Resources