Page 1 of 1

using javascript to alter link attributes in mozilla firefox

Posted: Mon Aug 23, 2004 8:37 pm
by d_d

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>links</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<script type="text/javascript">
<!--
function preview()
&#123;
	document.getElementById("preview").innerText = document.add_link.text.value;
	document.getElementById("preview").title = document.add_link.title.value;
	document.getElementById("preview").href = document.add_link.href.value;
&#125;
//-->
</script>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<link href="style.css" type="text/css" rel="stylesheet">
</head>
<body>
<form name="add_link" action="link.php" method="post">
<div>preview : <a id="preview" href="" title=""></a></div>
<div><br>href <input type="text" size="67" name="href" value="http://"></div>
<div><br>title <input type="text" size="67" name="title"></div>
<div><br>text <input type="text" size="67" name="text"></div>
<div><br><input type="button" value="preview link" onclick="javascript:preview()"></div>
</form>
</body>
</html>
I have a page that allows me and other visitors to submit links that are randomly show at the bottom of each page.
The problem is the preview doesn't work in firefox as it uses stuff only available to msie. I did a bit of searching and I can't see anyway to alter the link attributes that will work with firefox. Is there anyway to get it to work with both msie and firefox?

Posted: Mon Aug 23, 2004 8:55 pm
by feyd
try innerHTML

Posted: Tue Aug 24, 2004 10:52 am
by d_d
Thanks :) got it working now.

Code: Select all

<script type="text/javascript">
<!--
function preview()
&#123;
   document.getElementById("preview").href = document.add_link.href.value;
   document.getElementById("preview").title = document.add_link.title.value;
   document.getElementById("preview").innerHTML = document.add_link.text.value;
&#125;
//-->
</script>