admin管理员组文章数量:1026289
if I have a JavaScript method called getSomeStringValue()
, is there a way to pull that value and use it as the href
of a link, something like as follows?
(I'm aware the following code does not work.)
<a href="$:getSomeStringValue()" target="_blank">
My Link
</a>
if I have a JavaScript method called getSomeStringValue()
, is there a way to pull that value and use it as the href
of a link, something like as follows?
(I'm aware the following code does not work.)
<a href="$:getSomeStringValue()" target="_blank">
My Link
</a>
Share
Improve this question
edited May 10, 2011 at 18:57
Paul D. Waite
99k57 gold badges203 silver badges271 bronze badges
asked May 10, 2011 at 18:52
WEFXWEFX
8,5728 gold badges69 silver badges104 bronze badges
3 Answers
Reset to default 6I think this would work:
<a href="#" target="_blank" id="mylink">
My Link
</a>
<script>
document.getElementById("mylink").href = getSomeStringValue();
</script>
Just do this:
<a href="javascript:getSomeStringValue()" target="_blank">
My Link
</a>
And in getSomeStringValue()
you can do:
function getSomeStringValue(){
//some code
window.location = somewhere;
}
I used the idea posted by @Neal, and tweaked it a bit. This was the code I ended-up using if anyone's curious...
<a href="#" onclick="$:loadNewURL(parameter1, parameter2)">
My Link
</a>
<script>
function loadNewURL(parameter1, parameter2) {
var newURL = "http://";
if (parameter1 == "Some Value")
window.location = newURL + "/somepageA.aspx?detail=" + parameter2;
else
window.location = newURL + "/somepageB.aspx?info=" + parameter2;
}
</script>
if I have a JavaScript method called getSomeStringValue()
, is there a way to pull that value and use it as the href
of a link, something like as follows?
(I'm aware the following code does not work.)
<a href="$:getSomeStringValue()" target="_blank">
My Link
</a>
if I have a JavaScript method called getSomeStringValue()
, is there a way to pull that value and use it as the href
of a link, something like as follows?
(I'm aware the following code does not work.)
<a href="$:getSomeStringValue()" target="_blank">
My Link
</a>
Share
Improve this question
edited May 10, 2011 at 18:57
Paul D. Waite
99k57 gold badges203 silver badges271 bronze badges
asked May 10, 2011 at 18:52
WEFXWEFX
8,5728 gold badges69 silver badges104 bronze badges
3 Answers
Reset to default 6I think this would work:
<a href="#" target="_blank" id="mylink">
My Link
</a>
<script>
document.getElementById("mylink").href = getSomeStringValue();
</script>
Just do this:
<a href="javascript:getSomeStringValue()" target="_blank">
My Link
</a>
And in getSomeStringValue()
you can do:
function getSomeStringValue(){
//some code
window.location = somewhere;
}
I used the idea posted by @Neal, and tweaked it a bit. This was the code I ended-up using if anyone's curious...
<a href="#" onclick="$:loadNewURL(parameter1, parameter2)">
My Link
</a>
<script>
function loadNewURL(parameter1, parameter2) {
var newURL = "http://";
if (parameter1 == "Some Value")
window.location = newURL + "/somepageA.aspx?detail=" + parameter2;
else
window.location = newURL + "/somepageB.aspx?info=" + parameter2;
}
</script>
本文标签: How do I add a JavaScript result to a static HTML href attributeStack Overflow
版权声明:本文标题:How do I add a JavaScript result to a static HTML href attribute? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745629382a2160065.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论