Using current url in a javascript function

This question already has an answer here:

  • Get the current URL with JavaScript? 18 answers

  • window.location.href contains the current URL of the page.

    So your function should look like this:

    function twitterShare(){
        window.open('http://twitter.com/intent/tweet?text=Check this out here: ' + window.location.href,
                    "twitterWindow", "height=380,width=660,resizable=0,toolbar=0,menubar=0,status=0,location=0,scrollbars=0")
        return false;
    }
    

    You can use window.location.href . It holds the value of the current page you are on.

    链接地址: http://www.djcxy.com/p/22540.html

    上一篇: Javascript代码,将显示完整的网页网址

    下一篇: 在javascript函数中使用当前网址