2013-10-10 14:51
浏览 393


i want to open a new window on click of 1

$leadID = "<a href=', myWin, scrollbars=yes, width=400, height=650);'>1</a>";

it is not showing me error. is there any other way to open new window.

here is the fiddle

Thanks in advance.

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • doulu2591 2013-10-10 14:54

    Try onclick function separately it can give you access to execute your function which can be used to open up a new window, for this purpose you first need to create a javascript function there you can define it and in your anchor tag you just need to call your function.


    function newwin() {          'lead_data.php?leadid=1','myWin','width=400,height=650')

    See how to call it from your anchor tag

    <a onclick='newwin()'>Anchor</a>


    Visit this jsbin

    May be this will help you a lot to understand your problem.

    解决 无用
    打赏 举报
  • doujizhong8352 2013-10-10 14:53

    Use the onclick as an attribute of your a, not part of the href

    <a onclick='"lead_data.php?leadid=1", myWin, scrollbars=yes, width=400, height=650);'>1</a>


    解决 无用
    打赏 举报
  • duanchan5458 2013-10-10 15:00

    You should read up on the onclick html attribute and the documentation. Below is what you want.

    <a href='#' onclick='"", "myWin", "scrollbars=yes,width=400,height=650"); return false;'>1</a>


    解决 无用
    打赏 举报
  • dtvfshi5248 2013-10-10 15:27

    Fun! There are a few things to tease out here:

    • $leadID seems to be a php string. Make sure it gets printed in the right place. Also be aware of all the risks involved in passing your own strings around, like cross-site scripting and SQL injection vulnerabilities. There’s really no excuse for having Internet-facing production code not running on a solid framework.
    • Strings in Javascript (like in PHP and usually HTML) need to be enclosed in " or ' characters. Since you’re already inside both " and ', you’ll want to escape whichever you choose. \' to escape the PHP quotes, or &apos; to escape the HTML quotes.
    • <a /> elements are commonly used for “hyper”links, and almost always with a href attribute to indicate their destination, like this: <a href="">Google homepage</a>.
    • You’re trying to double up on watching when the user clicks. Why? Because a standard click both activates the link (causing the browser to navigate to whatever URL, even that executes Javascript), and “triggers” the onclick event. Tip: Add a return false; to a Javascript event to suppress default behavior.
    • Within Javascript, onclick doesn’t mean anything on its own. That’s because onclick is a property, and not a variable. There has to be a reference to some object, so it knows whose onclick we’re talking about! One such object is window. You could write <a href="javascript:window.onclick = location.reload;">Activate me to reload when anything is clicked</a>.
    • Within HTML, onclick can mean something on its own, as long as its part of an HTML tag: <a href="#" onclick="location.reload(); return false;">. I bet you had this in mind.
    • Big difference between those two kinds of = assignments. The Javascript = expects something that hasn’t been run yet. You can wrap things in a function block to signal code that should be run later, if you want to specify some arguments now (like I didn’t above with reload): <a href="javascript:window.onclick = function () { ... ) };"> ....
    • Did you know you don’t even need to use Javascript to signal the browser to open a link in a new window? There’s a special target attribute for that: <a href="" target="_blank">Google homepage</a>.

    Hope those are useful.

    解决 无用
    打赏 举报

相关推荐 更多相似问题