Issue
I'm trying to make a link that shows a glossary popup when you click it. It should run a script that changes the variable "WordId" to the html element id of the heading that corresponds to the definition of the word.
I tried this:
<a onclick="BrowserPopupGlossary()" onclick="WordId = "...";">...</a>
This is the BrowserPopupGlossary function:
var WordId;
function BrowserPopupGlossary() {
window.open('glossary.html'+'#'+WordId,'popUpWindow','height=500,width=400')
}
Any advice on how to optimize / fix this?
Solution
If that value is known at all at that time then just pass it to the function. There's no need for a global variable here, and certainly no need to try and create two onclick
handlers.
For example:
<a onclick="BrowserPopupGlossary('someValue')">...</a>
And use it in the function:
function BrowserPopupGlossary(wordId) {
window.open('glossary.html#' + wordId, 'popUpWindow', 'height=500,width=400');
}
Answered By - David
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.