Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update HTML Code When User Clicks Link on page

Status
Not open for further replies.

saw15

Technical User
Jan 24, 2001
468
US
I have created a home page, one with multiple links to various sites that I use on a daily basis. I have some friends that would like this page, but want the links and text changed as well as the title.

Is there a way to trigger on the existing link so the end user can change the link address as well as the text and title? I realize if the click the link as normal, it will take them there, but I am looking for a interactive way for them to change specific links as well as the text showing and the title.

Any example or thoughts would be appreciated.
 

So let me see if I've understood you. You've got your own page of links, and your friends want to customise it so that the link addresses and text are different?

Why not just give them the HTML file, and get them to edit it, and upload their own version of it?

Or have I missed the point?

Dan
 
You are correct, but the problem is that most of my friends / family are not computer literate at all and I don't care to give the same html instructions multple times (as I have already done so 3 times).

I think it would be easier to have them update the links if its possible to do it.
 

Even if you create some Javascript (etc) do let them update the links "live" on a website, they would still need to be able to upload that page to somehow - which would normally entail using either FTP software or a server-side solution anyway.

If they're not computer literate, are they going to be able to manage either of those? If not, I'm not sure any suggestion would work for them.

Don't get me wrong - I'm not trying to stamp on your ideas, but they will need to upload the page somehow, right?

Dan
 
The page will not have to be updated or uploaded, it sits on their harddrive and the browser points to the page, so that is not a concern.
 
If you have a server-side scripting environment available (php, jsp, asp, cfm) and some kind of database available to you (mySQL, SQL, Access) then you could do this by making a small "Content Management System" -- allowing them to edit the links and the text online (using their web browser) and in a very controlled environment.

I'm guessing this is not the case.

How about making a page that uses a form to allow them to customise links and text... they press the "Preview" button which runs a Javascript function to "massage" (convert into standard html) these new links and text into a textarea -- and they can then copy/paste the textarea contents to a blank text file (or email it to you etc).

If you have some server-side scripting langauge available you could submit the form to the server and (maybe) create a flat html file on the server for them. Just a thought.

Jeff
 

AFAIK, dynamically changing the content of a page is fine - and I can think of many ways to dynamically modify links, the link text, etc. But when saving that page, you'd need to somehow get the source code for the new links saved.

Viewing source would not help, nor would clicking "File" and "Save" - as only the original links would be updated.

The only thing I could possibly think of would be do get all the link updating done, generate innerHTML source in a textbox, get them to copy it, paste it in a new document, save it as an HTML file, and set that as their default start page.

Which seems like a whole lot of work for people you've already described as "not computer literate at all".

If you would still like me to post some code for dynamically changing link URLs and text, let me know.

Hope this helps,
Dan
 
Dan / Jeff,

Thanks for the feedback.

Dan, if you could post some code, maybe I could get an idea on what to do with the issue.

Thanks, SAW
 
Here's what I have:

Code:
<html>
<head>
	<script type="text/javascript">
	<!--
		function editLink(linkObj) {
			if (event.ctrlLeft) {
				var newURL = window.prompt('Please enter the URL for this link', linkObj.href);
				if (newURL != null) var newText = window.prompt('Please enter the text for this link', linkObj.innerText);
				if (newText != null) {
					linkObj.href = newURL;
					linkObj.innerText = newText;
				}
				document.forms[0].newCode.value = document.getElementById('links').innerHTML;
				return(false);
			}
		}
	//-->
	</script>
</head>
<body>
	<div id="links">
		<a href="[URL unfurl="true"]http://www.google.co.uk"[/URL] onclick="return(editLink(this));">Link 1</a><br />
		<a href="link2.html" onclick="return(editLink(this));">Link 2</a><br />
		<a href="file:////c:/test.txt" onclick="return(editLink(this));">Link 3</a><br />
	</div>

	<form>
		<textarea name="newCode" cols="75" rows="15"></textarea>
	</form>
</body>
</html>

If you click on any of the links, they go to where they should. If, however, you hold down the left-hand Ctrl key while clicking a link, you get the option of changing the link URL and text. After doing so, the HTML code for all the links is displayed in the box.

Hope this helps,
Dan
 
Thanks Dan.

That worked perfect, just what I was looking for.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top