View Full Version : adding rel attribute via javascript function href.

04-30-2007, 11:16 AM
Hello I am trying to create the link below but to launch it via javascript but to include a "rel" value to the window.open or window.href ?? or anyway it is possible...

the link i am trying to replicate,,,,

<a href="link.htm" rel="700 200" title="Caption">Link</a>.

i have trid something like this but nothing ...??? but not working or even close,, i have tried to read up on attribute.rel.. but can't find much..

<script type="text/javascript">
functions link(RelLink,Relvalue,Relname){
window.open(RelLink, ['rel', Relvalue], Relname, 0);

many thanks chris

04-30-2007, 12:07 PM
dunno why u want to set a rel attribute...better take a look here http://www.w3schools.com/htmldom/met_win_open.asp

04-30-2007, 12:15 PM
Hi thanks for the reply.. but w3schools doesn't give me the info I am after...

It might sound a little abnormal to want to include a rel value, but i need to do this to run some script i have to run from actionscript!!

don't pose anyone who may know could write an example...

04-30-2007, 06:01 PM
I have tried a few ideas but i still can't get it to launch the link from a javascript onclick to change the rel ???

here is what I have tried..

<script type="text/javascript">
function link(LinkName, RelValue){
x.rel = RelValue
window.href(LinkName, RelValue)

<a href="#" onclick="LinkName('link.htm','rel value')">test</a>

but man.. to have a link('page','rel value') is so hard... but to know how i can do this would be so so so so good :)

its a challange to you hardcore coders..

thanks you chris...

01-15-2009, 12:13 AM
I know you asked this question a few years back, but for anyone else looking to add the rel value into their code to utilize repeat functionality in DOM scripting cross site, here it is.

In my example, I am using a single div id and style to point my rss to many different dynamic rss zones on a website.

Here is the html.

<div id="subscribe-to-feed" rel="link to feed" class="float-right darklink">
<a href="link to feed" class="medtxt">subscribe</a><span class="margleftten"><img src="img/feed_ico.png" width="14" height="14" border="0"/></a>

Here is the JS

function dEI(obj){
return document.getElementById(obj);
(used to make life easier if not using the Prototype Lib, where the same is $)

dEI('subscribe-to-feed').onclick = function(){
window.location.href = dEI('subscribe-to-feed').getAttribute('rel');

This will allow you to use css,html, and javascript in your coding using the principles of semantic web standards. By separating the javascript, and css, you make your life as a coder easier, and can run a lot of real neat tricks in the background of your site, without having to tell the user looking through your html source what those are. Granted, anyone with Firebug running can look at your javascript, but then hey, you just look like a better coder).

In this example, I didn't want to have to wrap the rss icon in another link, and wanted the user to be able to click anywhere within the rss div region to get the the page, however, this is only good for people with javascript, so by adding a default anchor in the actual html, it depreciates rather well.

Scott Haines
California Website Design and Development - Standards Based Web Applications (http://www.newfrontcreative.com)