SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Inline Linking

  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2006
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Inline Linking

    Looking for a javascript to scan the contents of a page after loading and create links on the fly ala IntelliTXT - anyone seen anything like this?

  2. #2
    SitePoint Addict ALL's Avatar
    Join Date
    Oct 2005
    Location
    South Dakota
    Posts
    215
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    sounds like one of those ad things....

    anyway, i would fetch an array words to look for then search the document for those words, when found put an a link around it something like this...

    HTML Code:
    <html>
    
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>New Page 1</title>
    <script type="text/javascript">
    	search = ['hello',
    		'goodbye',
    		'something special',
    		'javascript',
    		'wsforums'
    	];
    	replace = ['http://www.wsforums.com',
    		'http://www.allada.com',
    		'http://www.tkforums.com',
    		'http://www.wikijs.com',
    		'http://www.wsforums.com'
    	];	
    	function do_your_magic(){
    		for(i=0;i<search.length;i++){
    			rege = new RegExp('(>[^<]*)('+search[i]+')([^>]*<)', 'gi');
    			tempstr = '>' + document.body.innerHTML + '<';
    			tempstr = tempstr.replace(rege, '$1<a href="'+replace[i]+'">$2</a>$3');
    			document.body.innerHTML = tempstr.substr(1, tempstr.length-2);
    
    		}
    	}
    </script>
    </head>
    
    <body onload="do_your_magic()">
    Here is an example on how you can use javascript to change text into a link. Something special about this is the fact is that it does not matter what the case
    is. It does not however, try and change things in tags... like: <a href="http://www.wsforums.com">my site</a>. This link was a link to start out with.</body>
    <br />
    <br />
    Goodbye!
    </html>
    Did I help you?
    You can repay me, support one of my projects (no money needed):
    JavaScript Wiki, Another Web Forum, Paranormal Site

  3. #3
    SitePoint Member
    Join Date
    Oct 2005
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there a way to modify this so that it will only create the link IF the text is not already linked to something?


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
  •