0

I already have pdf links set up. I am just looking to prepend Google's syntax in front of my current href using jQuery. i know the following doesn't work, but I feel I am close…?

jQuery(document).ready(function() {
jQuery("a[href$=.pdf]").attr("href", "http://docs.google.com/viewer?url=" + current.href);
});

Can anyway help, please?

1
  • 1
    Don't you mean this.href rather than current.href? Commented Apr 6, 2010 at 3:56

1 Answer 1

2

As long as you have absolute urls in the original document the following should work.

$(document).ready(function() {
    $("a[href$='.pdf']").each(function(){
        $(this).attr('href', 'http://docs.google.com/viewer?url=' + $(this).attr('href'));
    });
});​
Sign up to request clarification or add additional context in comments.

3 Comments

thanks admsteck! that's exactly what i was hoping to accomplish.
after further testing, this method doesn't seem to work with webkit browsers – safari and chrome. ideas?
Tested using jquery 1.3.2 and 1.4.2 and Google Chrome 4.0 over at jsfiddle

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.