It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

Javascript to create a link

Javascript to create a link

Postby FabianoM on Wed May 13, 2009 6:31 pm

Hello, I'm sorry for my English :D

I need to creat a link via javascript that pass the attribute rel:

I have the link:

Code: Select all
<a href="#page.php" rel="history">PAGE LINK</a>


I need something that call a javascript function, for example:

Code: Select all
<a href="javascript:pageURL('#page.php','history')>PAGE LINK</a>


where call the function


Code: Select all
function pageURL(url, rel){

}


I don't know how to create in this function, I need creat the link with the href and rel attributes inside this function, and that in it same function execute the link automatically.

I need to do it, because I have to call it in the getURL of my flash menu, because the getURl don't suport the attribute rel.

Somebody can help me??

Thank's
FabianoM
 
Posts: 6
Joined: Wed May 13, 2009 6:07 pm

Re: Javascript to create a link

Postby rangana on Thu May 14, 2009 5:26 am

What exactly are you trying to achieve?

You want to create a link that has an "inline" function on it via JS?

Please provide further info.
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 5:14 am
Location: Cebu City Philippines

Re: Javascript to create a link

Postby FabianoM on Thu May 14, 2009 1:30 pm

Hi, thak's for the answer...

I must call a function through my onclick to create the link, and on the same function executes the link created automatically.

Explaining:

my link should be only with the onclick, because I want to make a function that creates the link and executes it automatically, because I will use this function on getURL of the flash that not support to pass the rel attribute.

I have the link:

Code: Select all
<a href="#pagina.php" rel="history">PAGE LINK</a>


I want to transform it to something like this:

Code: Select all
<a href="#" onclick="pageURL('page name','rel attribute');">PAGE LINK</a>


And in the function "pageURL" I want to create the link with the href and rel attributes and after executes it automatically. I don1t know how to do it.

Thank's
FabianoM
 
Posts: 6
Joined: Wed May 13, 2009 6:07 pm

Re: Javascript to create a link

Postby rangana on Thu May 14, 2009 1:32 pm

Could you please provide your "pageURL" function.
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 5:14 am
Location: Cebu City Philippines

Re: Javascript to create a link

Postby FabianoM on Thu May 14, 2009 1:55 pm

Code: Select all
function pageURL(url, rel)
{
  var a=document.createElement('a')
  a.href=url
  a.rel=rel
  return a
}


But it is only returning the for me, I need to open the page automatically with this function as if it had been clicked in link.

Thank's
FabianoM
 
Posts: 6
Joined: Wed May 13, 2009 6:07 pm

Re: Javascript to create a link

Postby rangana on Thu May 14, 2009 2:07 pm

You want to create the link?

You need to "append" the created element instead.

Use appendChild(). For further reading:
http://www.webreference.com/js/column44 ... child.html

Hope that helps.
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 5:14 am
Location: Cebu City Philippines

Re: Javascript to create a link

Postby FabianoM on Thu May 14, 2009 2:25 pm

Thak's, but it wil only create the link on the page right?... I need that the link be created and executed automatically on the same function, opening the corresponding page.

thank's
FabianoM
 
Posts: 6
Joined: Wed May 13, 2009 6:07 pm

Re: Javascript to create a link

Postby rangana on Thu May 14, 2009 2:30 pm

You want to open the URL as passed on "url" argument?

Have you tried on using window.open() after appending the link?
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 5:14 am
Location: Cebu City Philippines

Re: Javascript to create a link

Postby FabianoM on Thu May 14, 2009 3:50 pm

No, Can you explain to me how to do it?? Sorry, but I'm not good in javascript.

Thak's
FabianoM
 
Posts: 6
Joined: Wed May 13, 2009 6:07 pm

Re: Javascript to create a link

Postby rangana on Thu May 14, 2009 3:55 pm

After you use the "appendChild()" function, you can add a line which would open the passed URL:
Code: Select all
window.open(url,'window_name','width=300,height=300');


Hope that helps.
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 5:14 am
Location: Cebu City Philippines

Next

Who is online

Users browsing this forum: No registered users and 4 guests