Web Development Questions That Don't Need Their Own Thread v2
3,079 replies, posted
How do I change a <li> class?
I have:
[code]
<li class="current_page_item_two"><a rel="#C40E3E" href="#">Home</a></li>
<li><a rel="#1123C6" href="#">About</a></li>
<li><a rel="#03C343" href="#">Gallery</a></li>
<li><a rel="#D1690E" href="#">Contact Us</a></li>
[/code]
And need to have the "current_page_item_two" change to a different <li> without reloading the site or anything.
jQuery .removeClass() and then .addClass()?
I need a good image uploader that will provide statistics of where people are viewing the image as well as what day/hour the image was viewed.
I could write one, but I'd rather use an existing one.
[QUOTE=adamjon858;30740472]I need a good image uploader that will provide statistics of where people are viewing the image as well as what day/hour the image was viewed.
I could write one, but I'd rather use an existing one.[/QUOTE]
Cant you just use google analytics?
It wouldnt tell you statistics if the user opens the image directly but then I dont know if you could even do that
I need to track image views in emails....
Anyone willing to help me sort the code from my template files? I'm just not good enough at PHP. :saddowns:
I can pay.
[QUOTE=jaybuz;30745234]Anyone willing to help me sort the code from my template files? I'm just not good enough at PHP. :saddowns:
I can pay.[/QUOTE]
If you can wait for about an hour, I'll help you out for free, jaybizznit.
tried reading tutorials/stuff about pdo
my head hurts from all this stuff
It's relatively simple, actually
Does anyone know what method/algorith imageshack use to resize images?
Another quick question..
I've got my main page, then I fetch new content from another page through AJAX. So when the user clicks on a menu entry, it'll replace a div with the content fetched from another PHP script. However I've got some canvasses and some jQuery stuff on that fetched content which doesn't seem to be working. For example I've got a div in this fetched content which I want to slide up when clicked, except it doesn't work when the page is fetched by AJAX. The canvas graphs also don't show up when fetched by AJAX. I tried putting
[code]
<script>
$(".notificationWidgetEntry").click(function() {
$(this).slideUp();
});
</script>
[/code]
at the top of the fetched content to see if that helped but it didn't seem to do anything. I'm guessing these sort of things are meant to initiate on page load and I guess when AJAX fetches it, it doesn't really count as a page load or something? Fuck, I don't know. How can I get these JavaScript things to work when the page is fetched by AJAX?
[editline]28th June 2011[/editline]
Actually it's not just those things, I can't get any Javascript to run on content fetched with AJAX.
You're browser only executes javascript on the page load, so when you do that ajax request that jQuery hasn't been executed. That's why it's not working. You'll have to move that jQuery into the page doing the ajax call. You MIGHT also need to use the .live() function to modify the elements being called with ajax
Hmm, I'd rather not have to bundle all the JS for all the pages into the main page. I was using non-jQuery XMLHTTPRequest and then setting the page content with the responseText variable, which doesn't retrieve Javascript. If I switch from standard XMLHTTPRequest to jQuery's .load() then it'll fetch the JS, but won't execute any of it. Someone suggested using .getScript() to then fetch the JS (after putting it in a seperate file) once I've fetched the HTML content. So I tried that, and I can get it execute the JS it fetches with getScript() for example a simple alert('hello') but the HTML5 canvas graphs just flash up for a split second then disappear, and my jQuery piece I posted earlier doesn't work either.. I must be doing something wrong here.
Have you tried putting the event handlers on the callback for .load()?
[code]
$('#contentarea').load('http://example.com/mypage.php', function() {
$('.notificationThingy').click(function() {
$(this).slideUp();
)};
)};
[/code]
Edit:
Just to clarify, the (generally) only rule about attaching events to DOM elements is that the element must exist when you make the attachment; callbacks are the best way to ensure the element exists.
I could do that but the load() isn't just going to load one page, it's requesting page.php?id=x where x will be a varying value, and each page is going to have different content and JS so I'd rather not have to throw all the pages' event handlers into that one load() call. I'm getting some weird behaviour right now, using the getScript() method I can load the JS, but it only works properly about 10% of the time.. the other 90% of the time the graphs appear for a split second then disappear, and my jQuery event handlers don't work. I'm really not sure what's causing this now.. all the javascript is doing when loaded is generating some graphs with the RGraph library and adding an event handler in jQuery.
[editline]28th June 2011[/editline]
Fixed! Your post made me realise that perhaps my scripts were not being called when the elements actually existed - I was retrieving the HTML content with load() then straight after calling getScript(). But I guess load is asynchronous and getScript() was running before load() had finished retrieving the content, and as you said you can't attach events to elements which don't exist yet, so I put getScript() as a callback to load() instead.Thanks!
-snip didn't see edit-
No problem!
I don't see the problem with putting all the JS on the main page. File size is nothing and if you add scripts below the body tag it doesn't stop the loading of the page.
[QUOTE=Richy19;30763653]Does anyone know what method/algorith imageshack use to resize images?[/QUOTE]
I don't know what method Imageshack use, but in my testing I've found the defaults that imagemagick use are very good (Mitchell Bicubic if the image has an alpha channel, Lanczos otherwise), but I also apply a very slight unsharp mask afterwards.
is this worth it? [url]http://www.amazon.com/Learning-MySQL-JavaScript-Step-Step/dp/0596157134[/url]
So I want to dynamically insert a script tag with javascript.
I can do that easy with document.createElement, but what I don't know how to do is insert the function in the script tag itself, e.g.:
[HTML]<script blah="bleh">
someFunction(); // < I want to add this
</script>[/HTML]
[QUOTE=vexx21322;30774704]So I want to dynamically insert a script tag with javascript.
I can do that easy with document.createElement, but what I don't know how to do is insert the function in the script tag itself, e.g.:
[HTML]<script blah="bleh">
someFunction(); // < I want to add this
</script>[/HTML][/QUOTE]
[code]
var script = document.createElement('script');
script.appendChild(document.createTextNode('(function() { doStuff() })();'));
document.head.appendChild(script);
[/code]
[QUOTE=deadeye536;30774785][code]
var script = document.createElement('script');
script.appendChild(document.createTextNode('(function() { doStuff() })();'));
document.head.appendChild(script);
[/code][/QUOTE]
Never would have thought to do it that way, thanks.
[QUOTE=vexx21322;30774955]Never would have thought to do it that way, thanks.[/QUOTE]
The "ChromeKludge" which is common among userscripts uses that method. I pretty much copied it. [url=http://stackoverflow.com/questions/2303147/injecting-js-functions-into-the-page-from-a-greasemonkey-script-on-chrome]Credit to the source![/url]
[QUOTE=deadeye536;30775317]The "ChromeKludge" which is common among userscripts uses that method. I pretty much copied it. [url=http://stackoverflow.com/questions/2303147/injecting-js-functions-into-the-page-from-a-greasemonkey-script-on-chrome]Credit to the source![/url][/QUOTE]
[del]Actually, it's not running the code. It's not error'ing.[/del]
[del]Hold on, this is weird.[/del]
Got it. I was over complicating things.
How can I strip the ".html" / ".php" from the end of the URL?
So for example; "domainname.com/home" instead of "domainname.com/home.html"
Is it done via .htaccess or can I use javascript or something?
Simple way would be to make a folder
domainname/home/index.html
also accessible as
domainname/home/
[QUOTE=garry;30778986]Simple way would be to make a folder
domainname/home/index.html
also accessible as
domainname/home/[/QUOTE]
ah so simple, thanks!
[QUOTE=garry;30778986]Simple way would be to make a folder
domainname/home/index.html
also accessible as
domainname/home/[/QUOTE]
Although this would work. You'd have to refer to all the resources as ../img/logo.png etc or have all of the resources copied into each folder which I wouldn't recommend.
[QUOTE=Chuushajou;30778754]How can I strip the ".html" / ".php" from the end of the URL?
So for example; "domainname.com/home" instead of "domainname.com/home.html"
Is it done via .htaccess or can I use javascript or something?[/QUOTE]
Just use htaccess its the easiest way
[code]
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
[/code]
This seems to be giving me 500 error on WAMP, but you should just look for a way to hide it through htaccess
Does work yyou just need mod_rewrite installed on apache
[editline]29th June 2011[/editline]
Are there any advantages or disadvantages for using ASP.Net form elements instead of the HTML ones?
[QUOTE=Jelly;30779269]Although this would work. You'd have to refer to all the resources as ../img/logo.png etc or have all of the resources copied into each folder which I wouldn't recommend.[/QUOTE]
I don't think that's an issue.. you should really be referring to your resources as /resource/name.png rather than relative to whatever folder you're in.
Sorry, you need to Log In to post a reply to this thread.