SitePoint Sponsor

User Tag List

Results 1 to 16 of 16

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Aug 2011
    Location
    Trinidad and Tobago
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Storing the value in a href tag

    how can I stored the value within an a href tag for example my php page does this
    Code:
    echo "<li><a href=\"JavaScript:article('$id')\">".$row['title']."</a> </li>";
    which prints this code on my ajax page
    Code:
    <a href="JavaScript:article('40')">What is the difference between Archiving and Trashing an Article? </a>
    . I want to save the value within href so that I can use it later. Please note its ajax so location.href doesn't work.

    Thanks

  2. #2
    SitePoint Zealot
    Join Date
    Aug 2011
    Location
    Trinidad and Tobago
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if I can store the entire link tag that wouldn't be an issue either. In fact that may be preferred.

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,603
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    Is that link intended to be saved as a bookmarklet? If not then get the JavaScript out of there and into a click event where it belongs.. The href should be used for where you want people without JavaScript to go when they click the link.

    Once you get the script out of the HTML and into a separate JavaScript file you will be able to more easily change it to work the way you want.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  4. #4
    SitePoint Zealot
    Join Date
    Aug 2011
    Location
    Trinidad and Tobago
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    Is that link intended to be saved as a bookmarklet? If not then get the JavaScript out of there and into a click event where it belongs.. The href should be used for where you want people without JavaScript to go when they click the link.

    Once you get the script out of the HTML and into a separate JavaScript file you will be able to more easily change it to work the way you want.
    Yes i want to use that link as a bookmark but when u click on it because it is ajax i dont see that in the address bar so i need a next way to save that value

  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by skelleex View Post
    Yes i want to use that link as a bookmark but when u click on it because it is ajax i dont see that in the address bar so i need a next way to save that value
    Virtually all web browsers prevent links from automatically saving as a bookmark, so the standard practice now is to instruct the user to drag the link to their bookmarks/favorites location.

    For an example, see http://delicious.com/help/bookmarklets
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  6. #6
    SitePoint Zealot
    Join Date
    Aug 2011
    Location
    Trinidad and Tobago
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    Virtually all web browsers prevent links from automatically saving as a bookmark, so the standard practice now is to instruct the user to drag the link to their bookmarks/favorites location.

    For an example, see http://delicious.com/help/bookmarklets
    Ok well I am not really trying to save this to the browser per say but to localStorage so that when the user visits this page again on there mobile phone the links deh favor can be accessed in its own bookmark section within the web app. Is that still not a preferred practice as I see no other way to save the users favorite articles. The drag and drop will not be favorable for all phones hence why I am asking this.

  7. #7
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by skelleex View Post
    Ok well I am not really trying to save this to the browser per say but to localStorage so that when the user visits this page again on there mobile phone the links deh favor can be accessed in its own bookmark section within the web app. Is that still not a preferred practice as I see no other way to save the users favorite articles.
    Local storage can be used, but it's available only with HTML5. What you could do is to check if local storage is available, and if it's not you could use cookies instead to store the info.

    Since your links contain javascript, you should serialize the data first, before saving it to either local storage or a cookie.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •