0
4

2 回答 2

1

将链接引用传递给getPDFpath函数。

<a href="PDFJS/pdfFile/DA_Chap02_v3.pdf"  onClick="getPDFpath(this)">DA_Chap02_v3</a>

您现在可以访问href元素的属性。

function getPDFpath(link){
    //navigate to another page by passing the href as the `pdflink` query param.
    location.href = 'my_other_page.html?pdflink=' + encodeURIComponent(link.href);
}

但是,您不必使用任何 javascript 代码来执行此操作:

<a href="my_other_page.html?pdflink=PDFJS/pdfFile/DA_Chap02_v3.pdf">DA_Chap02_v3</a>
于 2013-04-14T15:15:44.240 回答
0

以下是设置和获取 cookie 的功能。

function setCookie(key, value, exdays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + exdays);
    value = escape(value) + ((exdays === undefined) ? "" : "; expires=" + exdate.toUTCString());
    document.cookie = key + "=" + value + '; path=/';
}

function getCookie(key) {
    var i, x, y,
        ARRcookies = document.cookie.split(";");

    for (i = 0; i < ARRcookies.length; i++) {
        x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
        y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
        x = x.replace(/^\s+|\s+$/g,"");
        if (x == key) {
            return unescape(y);
        }
    }
}
于 2013-04-14T15:35:35.803 回答