Jump to content

Recommended Posts

I really need some help with this one.  I am confident it can be done easily, but i can not figure it out.

 

A very simplified look at my "announcements_current.php" page follows:

 

<div class=”main_nav”>

                <a href=”about.php”>About</a>

                <a href=”contact.php”>Contact</a>

                <a href=”resources.php”>Resources</a>

</div>

<div class=”announcement”>

     /* Announcement 1 */

     <p>For more information on this subject <a href=”/file_path/file0001.doc”>click here</a>.</p>

</div>

<div class=”announcement”>

     /* Announcement 2 */

     <p>For more information on this subject <a href=”/file_path/file0002.doc”>click here</a>.</p>

</div>

 

As the above page (announcements_current.php) loads it reads the mySQL database for current announcements, loops through each record and displays the page.  I would like to have all hyperlinks within the <div class="announcements"> rewritten on load to be <a href="file_open.php?aFile=/file_path/file0001.php">  (of course whatever the file name actually is).

My file_open.php  updates a database table with the date/time/user_id of when this file was accessed, then opens the file. 

 

Of course I do not want to rewrite any other hyperlinks not in the correct class.  I am sure this can be done, but i can not fire out how to accomplish this onload.  Can you help?

Edited by jostclan
Link to comment
https://forums.phpfreaks.com/topic/282017-rewrite-a-href-tags-on-load/
Share on other sites

kicken- These announcements are being created (added to the database) by staff using tinyMCE.  They select the insert hyperlink and pate the file file path.  They are not skilled enough, nor care enough to add the redirect.  I hope this helps answer the why.

Okay, consider this, then.

 

$(function(){
var links = $('a[href^="/file_path/"]').get(), i = 0;
for( i; i < links.length; i++ ) {
var h = links[i], var t = h.getAttribute("href").replace("/file_path/","/file_open?aFile=");
h.setAttribute("href",t);
}
});

kicken- These announcements are being created (added to the database) by staff using tinyMCE.  They select the insert hyperlink and pate the file file path.  They are not skilled enough, nor care enough to add the redirect.  I hope this helps answer the why.

kicken's suggestion was to have announcements_current.php generate the links the way you want them while building the page in the first place. So instead of echo $row['TextFromDB']; you would write a function to convert the links then echo ConvertLinks($row['TextFromDB']);.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.