How to get the name of the file itself - javascript

How to get the name of the file itself?
example i use tha code in bla.js and it will get the file name itself
and will echo bla.js
and how to split it?
Like if the file use [RE]xxx.js will true , and if just xxx.js will false
sorry for bad english

If you want to do it with node.js, then the filename is stred in __filename variable.

Related

How to read the txt file of the link taken in axios?

i want to read , text of file in rest API
i am using marked for convert txt to markdown and show to vue.js
But I do not know how to read the contents of the file
I also saw raw-loader in my search, but I do not know how to give contents of the file text in axios
You can use a syntax like below to read the text file:
axios.get('http://127.0.0.1:8000/markdownFile/test.txt').then(function(response){
this.markDownData = response.data
});
Then you can set the markDownData variable to your view

Get filename in dropzone using jQuery

hy guys I try like this, my quetion is how I can grab filename or name..?
console.log(myDropzone.files);
myDropzone.files returns an array of File objects. You could access specific file properties using index.
Eg.
console.log(myDropzone.files[1].name);//Getting second file name
Go to dropzone.js and find
Dropzone.prototype._finished() function and alert this
responseText.success
you will get the file name

Access Input id from the include page in php

I am trying to fetch the 'id1' mentioned on the different file. I have included the file using the include function. But does not get success. Can you please let me know where i am making mistake. Or is there another way to access this field
The detail is there underbelow
I have this text field in one file (file1.php) <input id ="id1" type = text" value ="location">
I have another file (file2.php), where i include the above file as <?php include("file1.php"); ?>
How can i access the 'id1' using document.getElementbyId. in file2.php
When i use it directly as document.getElementbyId('id1').value; its not coming.. Please help
The problem is that Javascript is case sensitive, and you're trying to use a method that doesn't exist.
Your B should be uppercase: document.getElementById

Call Javascript function from external file with Applescript

Is it possible to call a javascript file function in applescript? I can get it to work when written 100% in the applescript file or I can use "do javascript file some file". Is there a way to mix the two? Something like this:
tell application id "com.adobe.Photoshop"
tell current document
do javascript "function(Variable1,Variable1)" in file PathtoJSX
end tell
end tell
The function is located in the external file but I want to pass it variables from applescript.
Update:
I posted it when someone else ask but PathtoJSX is the "Path to Javascript file (.jsx)" so PathtoJSX = file "desktop:yourFile.jsx"
I think what you want to do is have the function part of the code in the file and send the arguments via AppleScript as a list (Array), which is pretty easy to do:
The contents of the jsx file could be:
testFunc(arguments);
function testFunc(t) {
alert('argument one: ' + t[0] + '\r' + 'argument two: ' + t[1]);
}
and the AppleScript could be:
tell application id "com.adobe.Photoshop"
activate
do javascript PathtoJSX with arguments {"foo", "bar"}
--I tested using:-- do javascript (choose file) with arguments {"foo", "bar")
end tell
Whatever you use for the JS code (text or file), you just make sure you use the arguments array reference in that code. Note that if you test this (as I did) by using a text variable instead of an alias (file reference), the return character would need a double escape.
Try this:
tell application "Adobe Photoshop CS4"
activate
do javascript (file "/Users/Michael/Desktop/somescript.jsx") with arguments {"foo", "bar"}
end tell
Regards.

How to update JavaScript variable using PHP

I have a JavaScript file named a pricing.js which contains this content in it:
var price_arr = new Array('$ 16.95','$ 30.95','$ 49.95','$ 70.95','$ 99.95','$ 109.95','$ 139.95','$ 155.95','$ 199.95','$ 460.95');
But I want to to update this part of JavaScript file using PHP so please help me in this how can I update this part of the content from JavaScript file using PHP?
'$ 16.95','$ 30.95','$ 49.95','$ 70.95','$ 99.95','$ 109.95','$ 139.95','$ 155.95','$ 199.95','$ 460.95'
Please understand that Javascript is Client Side code and PHP is server side code.
There can be 2 possible ways or scenarios which you want to achieve:
If you want to manipulate the JS file before sending it to client, you can rename the Javascript file to have .php extension and write php code to provide a variable. For Ex:
<?php
// write php code to create a string of values using a for loop
$price_array_string = "'$ 16.95','$ 30.95','$ 49.95',
'$ 70.95','$ 99.95','$ 109.95','$ 139.95','$ 155.95','$ 199.95','$ 460.95'";
// Javscript Code var price_arr = new Array(`<?`php echo $price_array_string ?>);
The other alternative is that you get the value of price array by making an Ajax Request to a PHP web service.
Simply give the pricing.js file a .php extension. You can then include PHP in the javascript file the way you would for any other page. Just be sure your HTML code specifies that it's still "text/javascript" when you load it. You'll probably want to set the content-type in the PHP file as well, like so: header("Content-type: text/javascript");
Using your PHP script you can put a value in an HTML5 data attribute of an element on your page and then read it from your JavaScript, e.g. <body data-array="'$ 16.95','$ 30.95'"> can be generated with PHP, and then read with JS: var are = new Array($('body').attr('data-array').split(',')). Here jQuery is used in order to read the attribute value, but you can also do it with pure JavaScript.

Categories

Resources