Jump to content

changing the href attribute of an <a> tag


tamanna35

Recommended Posts

Hello I am trying to change the value of href attribute. It gets changed, but clicking does not workI have a web application in which a page displays a file. The link to the file is database driven

<xsl:for-each select="//FileList/File"><a target="_new" name="FilePath" id="FilePath">	<xsl:attribute name="href"><xsl:value-of select="//FileLevel1"/><xsl:value-of select="//FileLevel2"/><xsl:value-of select="//FileFolder"/><xsl:value-of select="./FileName"/></xsl:attribute><xsl:value-of select="./FileName"/></a></xsl:for each>

Now in IE this works fine and clicking on the link opens the file.But when I am in firefox, the link is concatenated with "http://localhost:8222/ASPX/SiteStart.aspx"so'>http://localhost:8222/ASPX/SiteStart.aspx"so I am using a "onmouseover" to change the value of href.

<xsl:for-each select="//FileList/File"><a target="_new" name="FilePath" id="FilePath">	<xsl:attribute name="href"><xsl:value-of select="//FileLevel1"/><xsl:value-of select="//FileLevel2"/><xsl:value-of select="//FileFolder"/><xsl:value-of select="./FileName"/></xsl:attribute><xsl:attribute name="onmouseover">java script:BrowserVersion('<xsl:value-of select="./FileName" />');</xsl:attribute><xsl:value-of select="./FileName"/></a>

...........Browser version function looks like this (Filelevel 1, 2 and 3 are set as input types in page so i can use document.getElementByID)

function BrowserVersion (str)		{			var strVersion = new String(navigator.userAgent);var oFileLevel1 =document.getElementById("FileLevel1");var oFileLevel2 = document.getElementById("FileLevel2");var oFileLevel3 = document.getElementById("FileFolder");var strPath1 = new String(oFileLevel1.value);var strPath2 = new String(oFileLevel2.value);var strPath3 = new String(oFileLevel3.value);strPath = strPath1 + strPath2 +strPath3 +str;									var regExp;			if (strVersion.indexOf('Firefox') != -1)			{				if (strPath.substr(0,1) == ".")				{					strPath = strPath.substring(2);					strPath = strPath.replace(/\134/g, "/");				}				else				{	strPath ="file:///" + strPath;				}				document.getElementById("FilePath").href = strPath;			}			else 				document.getElementById("FilePath").href = strPath;		}

Now when I take my mouse on the file link, it shows me sorrect path. I know the path is correct because if I copy the link and paste in anothe tab it opens the document fine.But the problem is that when I click on it , nothing happens.Initially firefox was opening the link in another tab.Another problem is that because I have xsl for each, as there can be more then one file, the onmouseover event does not work for second link.when i take my mouse on it , it still shows me "http://localhost:8222/ASPX/SiteStart.aspx" concatenated with file path.I also tried document.links.[0] but no useSo why clicking on link does not make it open the file link. and how can I change the href attibute

Link to comment
Share on other sites

You're intermixing a lot of layers. You might want to more clearly separate them to find out where the problem is.For starters, view the XSLT generated source. In Firefox, you can do that with the Web Developer toolbar extension, and its "View Generated Source" option. In IE8, I think you can do that from the developer tools with F12. The DOM view, while not a text view will still let you see what the generated href value looks like.Knowing what happens in the end will let you determine the cause much more easily.

Link to comment
Share on other sites

You're intermixing a lot of layers. You might want to more clearly separate them to find out where the problem is.For starters, view the XSLT generated source. In Firefox, you can do that with the Web Developer toolbar extension, and its "View Generated Source" option. In IE8, I think you can do that from the developer tools with F12. The DOM view, while not a text view will still let you see what the generated href value looks like.Knowing what happens in the end will let you determine the cause much more easily.
I realized from the error console that the link is fine, but Fire fox does not allow this. It gives a security errorSecurity Error: Content at link.... may not load or link to file://///....The fire fox web site reports this bug on its site and suggests to change the user profile setting in about:config.but this is a webapp, many different users access this.Moreover I do not understand why it can access a file for example thishttp://web.engr.oregonstate.edu/~budd/Book.../bubblesort.cpp(some random file )and not my file, lying on a server.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...