The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

> redirection failed without jquery
jackmaessen
post Jan 23 2013, 03:11 PM
Post #1


Novice
**

Group: Members
Posts: 25
Joined: 17-January 13
Member No.: 18,471



I have this html file which should download a .zip file and redirect to, per example, google.com
CODE

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<!--<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>-->

<title>Download</title>

</head>
<body>

<a href="download.zip" id="download" target="_blank">Download file and redirect to google.com</a>

<script type="text/javascript">

$('#download').click(function() {
  window.location = 'http://www.google.com';
});

</script>

</body>
</html>

If i disable the jquery in the head, there will be no redirection to google.
I do not understand that.
It should still work even without the jquery?
Can someone explain me this?
What is the function of jquery?

This post has been edited by jackmaessen: Jan 23 2013, 03:12 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
 
Reply to this topicStart new topic
Replies(1 - 3)
pandy
post Jan 23 2013, 03:36 PM
Post #2


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,730
Joined: 9-August 06
Member No.: 6



The snip in the script block calls an event listener function in the jQuery file when the link with the id "download" is clicked and the window.location line runs, something like that anyway. Without the jQuery file that can't happen.

jQuery is what's called JavaScript library. A large file that contains a lot of canned JavaScript. Supposedly it makes it easier to use neat JS tricks than if you had to either write or find he individual scrips yourself. I'm no sure that is true. jQuery itself is pretty advanced JavaScript, so understand it by reading it directly is close to impossible if you aren't already pretty good at JavaScript. Instead you have to learn how to use jQuery, learn it's own syntax so to speak, without really knowing what you are doing. Just learn to push the right buttons. I lean towards that it's better to put that time on learning JS.

It's also overkill to load a large JavaScript library only to use a fraction of it, which is often the case. jQuery doesn't do anything that couldn't be done without it, only you need to either learn how to or find a (smaller) script that does what you want.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Jan 23 2013, 04:25 PM
Post #3


.
********

Group: WDG Moderators
Posts: 9,656
Joined: 10-August 06
Member No.: 7



Here's the equivalent with traditional java script:

CODE

<a href="download.zip" target="_blank" onclick="window.location = 'http://www.google.com';">Download file and redirect to google.com</a>
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
jackmaessen
post Jan 24 2013, 07:35 AM
Post #4


Novice
**

Group: Members
Posts: 25
Joined: 17-January 13
Member No.: 18,471



you are right; i did not notice i was using jquery and not plain js
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 23rd April 2024 - 08:24 AM