admin管理员组文章数量:1357281
This is my code:
var url = f.href.value;
ed.dom.setAttribs(e, {
href : 'javascript:void(0)',
onclick: 'doSomething(' + url + ')'
});
And the doSomething method:
function doSomething(url) {
windowMy = dhxWins.createWindow("externalLink", 10, 10, 630, 630);
windowMy.setText("Title");
windowMy.attachURL(url);
}
When doSomething is called, I get the error: Uncaught SyntaxError: Unexpected token :, when url="http://somewebsite/site".
What should I do? How can I pass url as parameter in JS function?
This is my code:
var url = f.href.value;
ed.dom.setAttribs(e, {
href : 'javascript:void(0)',
onclick: 'doSomething(' + url + ')'
});
And the doSomething method:
function doSomething(url) {
windowMy = dhxWins.createWindow("externalLink", 10, 10, 630, 630);
windowMy.setText("Title");
windowMy.attachURL(url);
}
When doSomething is called, I get the error: Uncaught SyntaxError: Unexpected token :, when url="http://somewebsite/site".
What should I do? How can I pass url as parameter in JS function?
Share Improve this question asked Sep 18, 2013 at 13:49 petko_stankoskipetko_stankoski 10.7k42 gold badges134 silver badges234 bronze badges 2-
2
The string you create is something like
something(http://...)
which is not a valid JavaScript function call. The argument has to be put in quotes to be interpreted as string literal. – Felix Kling Commented Sep 18, 2013 at 13:51 - 1 That is not jQuery, I have no idea what that is. – OneOfOne Commented Sep 18, 2013 at 13:51
1 Answer
Reset to default 7I think you just need some extra quotes around your url:
var url = f.href.value;
ed.dom.setAttribs(e, {
href : 'javascript:void(0)',
onclick: 'doSomething("' + url + '")'
});
Otherwise, the function ends up like this:
doSomething(http://www.google.);
Instead of:
doSomething("http://www.google.");
本文标签: javascriptPassing URL as parameter in JS functionStack Overflow
版权声明:本文标题:javascript - Passing URL as parameter in JS function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744059309a2583833.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论