Forums
This topic is locked
my article page
Posted 11 Nov 2005 15:31:37
1
has voted
11 Nov 2005 15:31:37 kralj uros posted:
I was searching the web for 2 hours and can't find a script or something similar to explain how to make following:On my webpage I have a link called my articles!
What I would like is to find or create a script, so that users can save favorite links, items, etc... into my article page using cookie.
So when they will return to my site they can click to my articles and all links which they have marked will be shown ( unless they didn't delete all cookies from the PC ).
So, does any1 here knows how to do it or where can I find a topic where it explaining??
Thanks,
Replies
Replied 11 Nov 2005 18:38:28
11 Nov 2005 18:38:28 myke black replied:
Hi,
Not sure whether you want people to create their own links by pasting the url into a form, or whether you want them to be able to bookmark pages within your own site. If you want to do the latter, then you can do it just using javascript by adding the following code to each page in your website:
<html>
<script>
// basic get and set functions for javascript cookies
function setCookie (cookieName, cookieValue, expires, path, domain, secure) {
document.cookie =
escape(cookieName) + '=' + escape(cookieValue)
+ (expires ? '; EXPIRES=' + expires.toGMTString() : '')
+ (path ? '; PATH=' + path : '')
+ (domain ? '; DOMAIN=' + domain : '')
+ (secure ? '; SECURE' : '');
}
function getCookie (cookieName) {
var cookieValue = null;
var posName = document.cookie.indexOf(escape(cookieName) + '=');
if (posName != -1) {
var posValue = posName + (escape(cookieName) + '=').length;
var endPos = document.cookie.indexOf(';', posValue);
if (endPos != -1) {
cookieValue = unescape(document.cookie.substring(posValue, endPos));
} else {
cookieValue = unescape(document.cookie.substring(posValue));
}
}
return cookieValue;
}
// custom code to store and remove links from the cookies
function storePage(){
thisPage = document.location.href;
var pageList = getCookie("pageList"
// check to see whether this url is already in the cookie's links list
var linkFound = false;
if (pageList != "" && pageList != null) {
pSplit = pageList.split(";"
for (a=0;a<pSplit.length;a++) {
if (pSplit[a] == thisPage) linkFound = true;
}
}
// if url not already in cookie, then add it here
if (!linkFound) {
if (pageList == null || pageList == ";" {
pageList = thisPage
} else {
pageList += ";" + thisPage;
}
}
// make the cookie expire in 1 years time:
var now = new Date();
var nextYear = new Date(now.getTime() + 1000 * 60 * 60 * 24 * 365);
setCookie("pageList",pageList,nextYear);
//refresh screen after link has been added
window.location.reload();
}
function removePage(url){
var pageList = getCookie("pageList"
var linkList = ""
// add each link to the linksList string and skip the one you want to remove
if (pageList != "" && pageList != null) {
pSplit = pageList.split(";"
for (a=0;a<pSplit.length;a++) {
if (pSplit[a] != url && pSplit[a] != '') linkList += ";" + pSplit[a];
}
}
// get the cookie expiry date
var now = new Date();
var nextYear = new Date(now.getTime() + 1000 * 60 * 60 * 24 * 365);
setCookie("pageList",linkList,nextYear);
// refresh screen after link has been removed
window.location.reload();
}
// code to write the list of urls to the page, and extra link to remove the url from the list.
function writeLinks(){
var pageList = getCookie("pageList"
if (pageList != "" && pageList != null) {
pSplit = pageList.split(";"
for (a=0;a<pSplit.length;a++) {
if (pSplit[a] != '' && pSplit[a] != 'null') {
document.write('<a href="' + pSplit[a] + '">' + pSplit[a] + '</a> <a href="javascript:removePage(\'' + pSplit[a] + '\')">[remove link]</a><br>');
}
}
} else {
document.write("There are no articles saved."
}
}
</script>
<body>
<a href="javascript:storePage()">Store this page</a>
<p>
Your current links list is:<br>
<script>
writeLinks();
</script>
</body>
</html>
Hope this is the sort of thing you were looking for.
If you want people to add their own links using a form, you can use the same code with slight modifications.
Not sure whether you want people to create their own links by pasting the url into a form, or whether you want them to be able to bookmark pages within your own site. If you want to do the latter, then you can do it just using javascript by adding the following code to each page in your website:
<html>
<script>
// basic get and set functions for javascript cookies
function setCookie (cookieName, cookieValue, expires, path, domain, secure) {
document.cookie =
escape(cookieName) + '=' + escape(cookieValue)
+ (expires ? '; EXPIRES=' + expires.toGMTString() : '')
+ (path ? '; PATH=' + path : '')
+ (domain ? '; DOMAIN=' + domain : '')
+ (secure ? '; SECURE' : '');
}
function getCookie (cookieName) {
var cookieValue = null;
var posName = document.cookie.indexOf(escape(cookieName) + '=');
if (posName != -1) {
var posValue = posName + (escape(cookieName) + '=').length;
var endPos = document.cookie.indexOf(';', posValue);
if (endPos != -1) {
cookieValue = unescape(document.cookie.substring(posValue, endPos));
} else {
cookieValue = unescape(document.cookie.substring(posValue));
}
}
return cookieValue;
}
// custom code to store and remove links from the cookies
function storePage(){
thisPage = document.location.href;
var pageList = getCookie("pageList"
// check to see whether this url is already in the cookie's links list
var linkFound = false;
if (pageList != "" && pageList != null) {
pSplit = pageList.split(";"
for (a=0;a<pSplit.length;a++) {
if (pSplit[a] == thisPage) linkFound = true;
}
}
// if url not already in cookie, then add it here
if (!linkFound) {
if (pageList == null || pageList == ";" {
pageList = thisPage
} else {
pageList += ";" + thisPage;
}
}
// make the cookie expire in 1 years time:
var now = new Date();
var nextYear = new Date(now.getTime() + 1000 * 60 * 60 * 24 * 365);
setCookie("pageList",pageList,nextYear);
//refresh screen after link has been added
window.location.reload();
}
function removePage(url){
var pageList = getCookie("pageList"
var linkList = ""
// add each link to the linksList string and skip the one you want to remove
if (pageList != "" && pageList != null) {
pSplit = pageList.split(";"
for (a=0;a<pSplit.length;a++) {
if (pSplit[a] != url && pSplit[a] != '') linkList += ";" + pSplit[a];
}
}
// get the cookie expiry date
var now = new Date();
var nextYear = new Date(now.getTime() + 1000 * 60 * 60 * 24 * 365);
setCookie("pageList",linkList,nextYear);
// refresh screen after link has been removed
window.location.reload();
}
// code to write the list of urls to the page, and extra link to remove the url from the list.
function writeLinks(){
var pageList = getCookie("pageList"
if (pageList != "" && pageList != null) {
pSplit = pageList.split(";"
for (a=0;a<pSplit.length;a++) {
if (pSplit[a] != '' && pSplit[a] != 'null') {
document.write('<a href="' + pSplit[a] + '">' + pSplit[a] + '</a> <a href="javascript:removePage(\'' + pSplit[a] + '\')">[remove link]</a><br>');
}
}
} else {
document.write("There are no articles saved."
}
}
</script>
<body>
<a href="javascript:storePage()">Store this page</a>
<p>
Your current links list is:<br>
<script>
writeLinks();
</script>
</body>
</html>
Hope this is the sort of thing you were looking for.
If you want people to add their own links using a form, you can use the same code with slight modifications.
Replied 14 Nov 2005 13:10:11
14 Nov 2005 13:10:11 kralj uros replied:
Thanks.....works great...
Just to tell you....I have added complete script on both pages!
first page where records are displayed ( without the show script )
Second page is a complete script but without adding the link to favorites.
The only thing I would like is to get the name of the article to be the displayed and not URL of the artice and date when the user added the url.
Also..when you add a article to favorites and page reloads..is it possibel to get a small text informing you your article was added?
How do I do that??
Edited by - kralj on 14 Nov 2005 13:21:37
Just to tell you....I have added complete script on both pages!
first page where records are displayed ( without the show script )
Second page is a complete script but without adding the link to favorites.
The only thing I would like is to get the name of the article to be the displayed and not URL of the artice and date when the user added the url.
Also..when you add a article to favorites and page reloads..is it possibel to get a small text informing you your article was added?
How do I do that??
Edited by - kralj on 14 Nov 2005 13:21:37