Solved

JQuery replacement of closing hyperlink tag if http is in the href tag

Posted on 2012-12-20
2
478 Views
Last Modified: 2012-12-20
I've been recently asked to modifiy how we redirect users from a site.  Currently we use a url variable on the asp .net page to redirect the user.  We validate and encode the data, but we were asked to make sure we know where we are directing the site.  Since it is virtually impossible to know that every site is valid when you allow a URL parameter to accept the target page, I need to come up with a different solution.

One thought would be to use javascript or Jquery to look at every link on the page and to determine if it includes http in the href.  If it does, then replace the closing tag with an image and some text that is hidden until hovered over.  I've got the code for the image and the hover, I just don't know how to implement the replacement of the closing </a> tag with the info we need to insert.

So for example, the desired action would be: <a href='http://www.google.com'>Google</a> would render to this:

<a href='http://www.google.com'>Google</a> <span class="dropt" title="Redirect Disclaimer"><img src='images/redirect.png' title='Redirect Disclaimer'/><span style="width:350px;">Text of the Disclaimer Here </span></span>


Here is the CSS to have the text show normally, and to appear when hovered over

span.dropt {/*border-bottom: thin dotted;*/ /*background: #ffeedd; */
      text-transform: None !important; float:right;}
span.dropt:hover {text-decoration: none; background: #ffffff; z-index: 6; }
span.dropt span {position: absolute; left: -9999px;
  margin: 20px 0 0 0px; padding: 3px 3px 3px 3px;
  border-style:solid; border-color:black; border-width:1px; z-index: 6;}
span.dropt:hover span {left: 7%; background: #ffffff;}
span.dropt:hover span.rightside {left: 45%; background: #ffffff;}
span.dropt span {position: absolute; left: -9999px;
  margin: 4px 0 0 0px; padding: 3px 3px 3px 3px;
  border-style:solid; border-color:black; border-width:1px;}
span.dropt:hover span {margin: 20px 0 0 170px; background: #ffffff; z-index:6;}
0
Comment
Question by:atljarman
2 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 38710344
Test page : http://jsfiddle.net/YykXJ/
Using :
$("a").filter(function() { return $(this).attr("href").indexOf("http")==0; }).after('<span class="dropt" title="Redirect Disclaimer"><img src='images/redirect.png' title='Redirect Disclaimer'/><span style="width:350px;">Text of the Disclaimer Here </span></span>');

Open in new window

0
 

Author Closing Comment

by:atljarman
ID: 38710431
Exactly what i needed.  Thank you.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Error in Angular 2 when showing in grid 4 25
Generate Unique ID in VB.NET 21 69
Input parameteres to DragOver 2 20
C# Service FileSystemwatcher isse 9 29
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
This video teaches users how to migrate an existing Wordpress website to a new domain.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question