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>
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745629384a4637010.html
评论列表(0条)