0

enter image description here

As mentioned above, i need to create a class="donate" that will be used in anchor tag which will redirect and pass the value of href to my another page i.e -mysite.com/donate.html,

where donate.html will be able to grab that href value . so that when user click on " continue to download" will be able to download the file .

Please let me know whether is it possible or not . I would prefer HTML and javascript only . as I don't host webpages i use blogger .

I've seen similar concept in templateism.com, something like:

www.templateism.com/p/preview.html?=www.templateism.com/10/2010/anypost.html

Shaym Murmu
  • 3
  • 1
  • 7

4 Answers4

1

you can use the link like:

mysite.com/donate.html?www.yoursite.com.otherpage.html

and then using javascript:

var href = document.location.href;
var link = href.split('?')[1];
Ashkan Mobayen Khiabani
  • 33,575
  • 33
  • 102
  • 171
0

Basically you need to pass the value you required in querystring like mysite.com/donate.htm?key=value.

On donate.htm page you can use this function mentioned here How can I get query string values in JavaScript? to fetch the value you supplied in querystring by passing the key.

Community
  • 1
  • 1
Dinesh Prajapati
  • 499
  • 3
  • 17
0

You can use the JavaScript (jQuery required) code below to attach a click event handler to all links with the donate class.

JS on page1.html and page2.html

$(document).ready(function() {
    $('a.donate').click(function() {
        // Retrieve the href value and store it in a variable.
        var href = $(this).attr('href');

        // Redirect a user to the desired page and passes the href value in query string.
        window.location.href = 'http://example.com/donate.html?href=' + href;

        // Ensure the original click event handler is not triggered.
        return false;
    })
});

After clicking a link the user will be redirected to the donate page where you can parse the query string and obtain the value of the href (which is what was in the <a href="..."> on the previous page).

There are many ways to parse the query string but the following quick&dirty code should work for you.

JS on donate.html

var location = document.location.href;
var queryString = location.split('?')[1];

// In the href variable is now what you are looking for.
var href = queryString.substr(5);
Anton
  • 2,458
  • 2
  • 18
  • 30
  • Thanks @Anton, if you don't mind can you please give me some small kind of tutorial for this, I'm still beginner . I mean where to add up these lines. – Shaym Murmu Jul 07 '16 at 11:52
0

Here try this For example...... This is your html code

<a href="http://example.com/donate.html?www.yoursite.com.otherpage.html"></a>

As Ashkan said, use his javascript to parse the previous url from it... Paste this code on donate.html

<script>
var href = document.location.href;
var link = href.split('?')[1];
window.location.href = "http://"+link;// This will show you the link
</script>

Hope this helps;

Utkarsh Dixit
  • 4,267
  • 3
  • 15
  • 38
  • Thanks @ It worked ! and it split the url after '?' Can you please tell how to redirect the user to that splited url . I mean how to redirect them to 'var link' when they click . – Shaym Murmu Jul 08 '16 at 07:39
  • It redirects to parents directory actual url :www.myexample.com/rd/donate.html?www.anothersite.com but it redirects to www.myexample.com/rd/www.anothersite.com i need : www.anothersite.com only – Shaym Murmu Jul 08 '16 at 10:33
  • @ShaymMurmu You need to http before the url try my code now. I have updated it. – Utkarsh Dixit Jul 08 '16 at 14:53