0

I am running a blog: http://jokesofindia.blogspot.com. I want to provide a dynamic link in the sidebar of my blog to download a Hindi newspaper in pdf format.

I tried to view source url of epaper.patrika.com and found that if I enter the url epaper.patrika.com/pdf/get/145635/1 it will download the first page and epaper.patrika.com/pdf/get/145635/2 it will download second page, and so on.

The last part of url is the page number. But the second to last part of the url, '145635', changes every day. Now I want to be able to enter this changing part of url manually every day and then have the JavaScript generate download links with the date replaced by the information I entered.

This code also needs to work on mobile devices such as Android.

4

1 回答 1

0

您可以使用 html5 数据对象来存储数据并使用 JS 获取该数据并将其附加到链接中:

HTML

<div class="linkholder" data-number="12345">
    <a href="epaper.patrika.com/pdf/get/#/1">PDF page 1</a>
    <a href="epaper.patrika.com/pdf/get/#/2">PDF page 2</a>
</div>

JS

$(document).ready(function() {
  var newNum = $('.linkholder').attr('data-number');
  $('.linkholder a').each(function() { 
    var newLink = $(this).attr('href').replace('#', newNum);
    $(this).attr('href',newLink);  
  });
});

查看CodePen以了解它的运行情况。

于 2013-08-09T19:08:54.693 回答