I need to be able to create a line that looks like this:
<script type="text/javascript" src="http://localhost/myapp/themes/testtheme/js/fancybox/jquery.fancybox.pack.js?v=2.1.2"></script>
I've tried the following:
Assets::add_js('fancybox/jquery.fancybox.pack.js?v=2.1.2');
but that fails - it doesn't add anything at all to my header.
Using:
Assets::add_js('fancybox/jquery.fancybox.pack.js');
adds a script tag, but without the version number. It just looks like this:
<script src="http://localhost/myapp/bonfire/themes/testtheme/js/fancybox/jquery.fancybox.pack.js" type="text/javascript" ></script>
Can you tell me how to add the ?v=2.1.2 to my script tag? Thanks!
I'm not too familiar with Bonfire, but I took a quick look at the source code.
I'm pretty sure the reason it's not displaying the script tag is because it's looking for a file with the literal name fancybox/jquery.fancybox.pack.js?v=2.1.2, which doesn't exist.
I think you can trick it by using a full url, so it thinks it's an external script and won't check if the file exists. Something like:
Assets::add_js(base_url().'fancybox/jquery.fancybox.pack.js?v=2.1.2');
It's never pleasant to have to use workarounds like this and can sometimes cause side effects, so I would suggest you point this out to the developer(s) of Bonfire.
Another thing to note, ?v=2.1.2 is nothing more than a cache-busting trick for when you update the file (it makes users re-download the file when the query string is changed), so consider whether or not you actually need it.
Related
If you visit this page in Chrome:
http://www.immigrationconsult.org/contact.php
And Inspect Element on the page, go to Console you will see this error:
GET htt...cms/contact/images/ajax-loader.gif 404 (Not Found) jquery.min.js:4
I followed the instructions here to create a:
http://css-tricks.com/weird-file-requests-and-easing-server-stress-with-htaccess/
I tested to make sure it works, and it does, but not on this specific request. jquery.min.js is the jQuery minified from the makers, I did not change it at all. I used Agent Ransack to deep search for any reference of this in any of my files, the search yielded no results.
I have no idea what to do or how to prevent this issue from happening, this seems like such a small issue, but I can not locate the cause of the problem! Please help.
So, it was really a misdirection by Chrome. The plugin at fault was jQuery Coda-Slider. Because it was JS compressed, Agent Ransack couldn't find the string... lesson learned...
You clearly don't have the ajax-loader.gif file in the correct directory, or at least your ajax script is looking the wrong place.
you can either modify the java script to point to the right location or you can just put the file in the correct location, i would choose the latter.
I have had these errors my self with JQuery, where some icons didn't get loaded, just had to put them in the correct folder and it worked.
But if you use googles jquery libs, all resources should get loaded automagic as well. Like this...
<script type="text/javascript"
src="http://www.google.com/jsapi">
</script>
<script type="text/javascript">
google.load("jquery", "1.7.2");
google.load(etc..);
</script>
You need to download the entire zip file from their website: http://jquerymobile.com/download/. After you unzip it, you will find the js file, the CSS and a folder called "images", all of which need to be present locally.
i wrote like this as follow in a php file (for example: a.php)
<script src="scripts/a.js"></script>
<div>
.....
</div>
I can guarantee that the path of js file is right, because i can see the js content in firebug HTML-view. However, in Script-view there isn't a.js. It seems that a.js has been added into the html but can't be loaded, but some other js files can be recognized. And if I paste the js content directly in the DOM, it works.
I'd like to know when doesn't work and why? thanks a lot~
Answer: There's some serious syntax errors in my js file. The error may be too serious for the browser to recognize it...
I can't give you a positive answer as there's very little details, but you should use an absolute path to your JavaScript.
<script src="/scripts/a.js"></script>
I'm working with my JS files, what i have now is a unique php file with JS header, if a variable is set it includes the real js file, which is fine.
The "home" page has the script tag for the php-js file:
<head>
<script type="text/javascript" language="javascript" src="bootstrap.php"></script>
</head>
the bottstrap.php file has something like:
if(isset($hostData) && !empty($hostData)) {
include('bootstrap.js');
}else {
echo "document.write('<center><bold>PLEASE DO SOMETHING...!</bold></center>');";
}
all that seems to be fine, however when viewing the source code (CTRL+U) the browser shows the "bootstrap.php" part as a link, if clicked it obviously redirects to http://mydomain/bootstrap.php and the js code can be easily seen, which is exactly what i don't want...
So my question is, is there any php-way to know if the file is being loaded from browser's "rendering view" or being loaded from browser's "source code view" ???
Any help is truly appreciated =)
In short, no. You can't hide your script source from your users. The best you can do is obfuscate it using tools like YUICompressor.
There's no way you can hide the javascript code. It needs to be executed by the client, and even if you try to hide it by formatting your code badly, tools like firebug can easily introspect the code and pull out the code.
To be honest I don't think you can actually hide it like that. I'm assuming the best thing you've got to go on is the useragent string but I'm assuming if you "view source" in a browser it would still send the regular headers.
The only way I can think of adding the JS include without it appearing when in view source mode is to actually load the external file via javascript (you could even break the path of the js file into variables so it isn't really human readable) which I would not advise.
If someone wants to get at your javascript they will there no is way of avoiding it.
and the js code can be easily seen, which is exactly what i don't want...
You don't want the JS to be seen, but you do want to use it???
There IS something wrong with your code though if you want the js file to be used in your page.
You need to include / require the file:
<script type="text/javascript" language="javascript" src="<?php include bootstrap.php ?>"></script>
Otherwise the browser will load the contents of the bootstrap file, but you want to run the code inside it (which can only be done at the server).
Also:
change:
include('bootstrap.js');
to
echo bootstrap.js;
EDIT
by re-reading your question (and other answers) that's exactly what you want: make your JS code invisible (correct me if wrong).
The answer to that is: No cannot be done.
You can try to obfuscate the code but it will take someone who wants to see it seconds to 'decode'.
Try using the $_SERVER["HTTP_referer"], which have the url that called this file.
I'm really sorry for disappearing from here...
The best solution I decided to implement is quite simple: don't show ANY URL or PHP files within JS code; so during last months I've used a unique PHP file to do all necessary database queries, a stored procedure generates dynamically all the URL's needed from JS.
In that way URL's vary every time and what I've named "poor logic" goes free for users to view/copy I don't mind that while server data is secure.
THANKS ALL FOR YOUR VALUABLE ANSWERS!!!
i know, this looks stupid, but i am a new one in scripting so please help, i want my src not be ending with file with extension. like:
<script src="mysite.com/dir/"></script>
and NOT like this:
<script src="mysite.com/dir/script.js"></script>
is this done with HTACCESS or with what?
P.S. I want to create something like a hitcounter and dont want athers to see my script code
here is an sample:
<script type="text/javascript" src="http://topsite.ucoz.com/stats"></script>
if you run this in html it will sent a mini banner and an hiden iframe with that page.
Use url rewrites in your .htaccess like this:
RewriteEngine On
RewriteRule ^dir/$ /dir/script.js [NC]
The problem with this is that /dir/ cannot be used for anything else.
What you could do is something like this:
RewriteEngine On
RewriteRule ^script/$ /dir/script.js [NC]
However this does not solve the problem of people seeing your code at all.
The only solution to that is either code obfuscation or using php (or some other server-side language)
You can configure your web server to have a default page when you call a directory.
This is usually done for index.html, index.php, ...
And here say this default is script.js the server should then deliver it by default
The first one is to a directory and not a file. It doesn't really make sense unless your thinking how on most servers http://abc/index.html goes to http://abc/
Cant really do it and cant see why you'd want to.
Either use the htaccess code listed to rewrite your url or simply fill your index.php with javascript.
and actually, using a url-rewrite would make it pointless having an index.php/index.html there in the first place.
mysite.com/page.php:
<script type="text/javascript" src="/dir/"></script>
mysite.com/dir/index.php:
alert('hello world');
also the sample you listed shows an example of someone using a file, not a whole directory. they simply leave off the extension to their file. Extensions only have semantic value.
I think the main goal here is 'to hide javascript from the user' right?
If you want to hide a javascript, you may want to lookup for 'javascript obfuscation'.
You can't really hide javascript, because it must be able to run on the client browser.
Even if you set the default url, as answers stated above, the javascript file will be downloaded.
However, you can obfuscate javascript files so that it will be hard for humans to read while machines can execute it.
There is a question in SO that ask about it.
How can I obfuscate (protect) JavaScript?
I am using a WP template that allows me to incorporate arbitrary HTML. Unfortunately, I have to use this particular widget and can't use other WP widgets.
I have on my webserver /some/path/serve_image.php that spits out a random HREF'd IMG SRC with a caption and some other info from a MySQL query.
Now...how can I say "take that output and treat it as HTML"? If I just put "/some/path/serve_image.php" I get that literal string.
I tried:
<script type="javascript" src="/some/path/serve_image.php"></script>
but that didn't work. I tried changing everything in serve_image.php to be document.write() calls and that didn't seem to work either. I'm not the world's greatest JS guy...
So if I have a URL on the net that spits out some HTML and I want to include that HTML in my web page, what's the best way to do that? Sort of like what Google does with Adsense - you source their show_ads.js.
Why no? Add
header('Content-Type: application/javascript');
And output JavaScript Like:
echo("var image = \"".$images[array_rand($images)]."\";");
echo("$('img.randim').attr('src', image);
No. JavaScript and PHP are two completely separate languages. In fact, if it was JavaScript, you aren't even loading it the right way.
<script type="text/javascript"></script>
The way you're trying to do it would throw a parse error, because it would try to use the PHP as JavaScript. Some browsers would even reject it, because PHP files have a text/html MIME type, while JavaScript should be application/javascript.
PHP has to be done server side, so loading it in the client just doesn't work.
What I think you're after is this:
<?php
require('/some/path/serve_image.php');
?>
Just place that wherever you want the image to be.