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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CreateElement Target Attribute not setting 1

Status
Not open for further replies.

simonchristieis

Programmer
Jan 10, 2002
1,144
GB
I am trying to create a vml element, and set it's target sttribute to _blank, however theis attribute is not being set.

I have recently changed from using innerHtml to create the vml which worked, but wanted to use dom.

any ideas anyone?

Simon

Code:
<snipped>

var vml = document.createElement("v:roundrect");
cell[cellCount].appendChild(vml)
vml.href = nH.item(lID).attributes.getNamedItem("url").value;
vml.target = "_blank";
vml.style.width = "10pt";
vml.style.height = "8pt";
vml.fillcolor = fColor;


 
how about
vml.setAttribute("target", "_blank");


=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
 

I've no idea if this will work or not, but have you tried this?:

Code:
vml.setAttribute('target', '_blank');

Hope this helps,
Dan
 
Thanks both, but that's not working either.

I have checked on msdn and vmln shapes support the target attribute, so therefore they should allow it to be changed, previously I created the elements using innerHTML, I guess I might have to go back to that.

Perhaps it is a bug with ie, if you 2 don't know, I guess no one does.

Thanks again

 
Longshot, but do you have an XML namespace? Not sure if it makes any difference or not (cluthcing at straws here ;o).. Something like this:

Code:
<html xmlns:v="urn:schemas-microsoft-com:vml">

Dan
 
yes, unfortunately. ;o(

<HTML xmlns:v="urn:schemas-microsoft-com:vml">
 
Got it! Specify the target when you create the element. The blue rectangle now opens in a new window:

Code:
<html>
<head>
	<xml:namespace ns="urn:schemas-microsoft-com:vml" prefix="v"/>
	<style>
		v\:* { behavior: url(#default#VML); }
	</style>
	<script type="text/javascript">
	<!--
		function createShape2() {
			var myVml = document.createElement('<v:roundrect target="_blank">');
			document.getElementsByTagName('body')[0].appendChild(myVml);
			myVml.href = '[URL unfurl="true"]http://www.yahoo.co.uk/';[/URL]
			myVml.style.width = '50px';
			myVml.style.height = '50px';
			myVml.fillcolor = '#0000FF';
		}
	//-->
	</script>
</head>
<body onload="createShape2();">
<v:rect id="myRect1" href="[URL unfurl="true"]http://www.google.co.uk/"[/URL] target="_blank" fillcolor="#FF0000" style="height:50px;width:50px;"></v:rect>
</body>
</html>

Not bad for my first attempt at VML ;o)

Dan
 
Dan,

Not bad at all for a first attempt - I just didn't know what to do next, obviously a star for your help, and a big thank you.

Simon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top