问题
this is specific to A-Frame.
I'm creating an a-link from javascript code:
var alinkEl = document.createElement('a-link');
alinkEl.setAttribute('href', 'http://www.facebook.com/share.php?u=https://.../' + folder + fileName);
This does not work:
alinkEl.setAttribute('target', '_blank');
Any hint?
回答1:
The <a-link>
s are intended for link traversal as far as i know, not for opening new tabs. The component does not have a target
attribute in the schema. Furthermore, the navigation is implemented like this:
navigate: function () {
window.location = this.data.href;
}
So You only change the location of the given window.
To open a new tab I would would do the portal, and the link myself:
If You want a portal use the
portal
shader, and set the pano
attribute:
<a-circle position="0 3.5 -2"
material="shader:portal;pano:_URL_TO_PORTAL_IMAGE"
></a-circle>
If You want it to open a new tab, make Your own component:
AFRAME.registerComponent('foo', {
init: function() {
this.el.addEventListener('click', (e) => {
window.open('https://ebay.com');
})
}
})
And attach it to Your portal:
<a-circle position="0 3.5 -2" material="shader:portal;pano:_URL_TO_PANO"
foo></a-circle>
Working fiddle here.
回答2:
It looks like the <a-link>
primitive does not have the "target" attribute.
But there is an npm package that supports that. It's called aframe-href-component and can be found here: https://www.npmjs.com/package/aframe-href-component
回答3:
a-link does not support a target
property according to https://aframe.io/docs/0.6.0/components/link.html
来源:https://stackoverflow.com/questions/45956178/a-frame-how-to-open-a-dynamically-created-a-link-in-a-blank-page