如何制作一个JavaScript书签来添加到URL的一部分?
How do I make a JavaScript bookmarklet to add to part of the URL?u
我正在尝试制作一个JavaScript书签来转到我的数学书的下一页。URL是website.com/book_year_pagenumber.pdf
,所以第500页应该是website.com/book_year_0500.pdf
。
我需要一些东西添加1到500使其website.com/book_year_0501.pdf
,但它必须在任何页面上工作,如从第200页到201页或第573页到574页。有人知道怎么做吗?
编辑:也许这将帮助。我想让它变成http://my.hrw.com/math06_07/student/pdf/english/alg2/alg2_07_0500.pdf成"http://my.hrw.com/math06_07/student/pdf/english/alg2/alg2_07_0501.pdf"
javascript:(function(){var url=location.href.split('book_year_');var currentPage=+(url[1].split('.')[0])+1;while(currentPage.toString().length<4){ currentPage='0'+currentPage;}location.href=url[0]+('book_year_')+currentPage+'.pdf';})()
不行吗?
略读:
// declare that this bookmarklet is a js script
javascript:(function(){
// parse the current url
var url = location.href.split('book_year_');
// get the page number, transform it to a Number and increment it
var currentPage = +(url[1].split('.')[0])+1;
// add the leading zeroes
while(currentPage.toString().length<4){ currentPage = '0' + currentPage;}
// set the new url
location.href= url[0]+('book_year_')+currentPage+'.pdf';
// call the function
})()
相关文章:
- 动态地改变“”的URL;添加新项目”;链接使用javascript/jquery
- 将url替换为链接,但添加了困难
- 如何从 URL 数组向文档添加图像列表
- 单击引导模式锚点时添加 URL 哈希
- Javascript,Jquery-添加url图像
- Jquery在尝试添加url参数时添加哈希符号
- 如何在javascript中添加url
- 使用 Angularjs 中的单选按钮动态添加 url 和 alt 属性
- 如何使用 css 元素从 java 添加 url 链接
- 如何通过 css 元素从 jquery 添加 url 链接
- 在提交表单时停止添加URL参数
- 如果JSON对象中没有提供,如何向ng重复添加Url
- 如何使用对话框/提要javascript在Facebook的描述字段中添加URL
- 如何在新页面上添加URL值
- 根据Iframe的ID,为Fancybox2-AJAX调用的Iframe添加URL
- 为文档中的链接添加URL参数
- 更改下拉菜单,在输入框中添加url参数
- 通过Angular Script添加URL
- 是否可以在window.history对象中添加url
- Javascript google api调用-如何添加“url丢失”如果响应中没有图片url,则返回json obj