开发者

Javascript alert message contains URL

I am using the following javascript function:

<!-- Notifying 开发者_JAVA百科message at the beginning of openning the website -->
    <script language="javascript" type="text/javascript">
        alert('Sorry!');
    </script>
    <!--End -->

I want to add the URL after "(Sorry!)" in the alert message but I don't know how to append the URL to the message itself inside the javascript.


Try -

alert('Sorry!'+document.URL);

Demo - http://jsfiddle.net/ipr101/Fg3eN/


You want to use the window.location object to get the current value.

 alert('Sorry! ' + window.location.href);


If you mean URL:

<script language="javascript" type="text/javascript">
    var url = "http://www.google.es/";
    alert('Sorry!' + url);
</script>

If you mean a link, the answer is that it is not possible.


This will put the current URL in the alert box. Note that it will not be a hyperlink that is clickable.

<script language="javascript" type="text/javascript">
        alert('Sorry! ' + window.location.href);
    </script>


document.location.href or document.URL, both will work :)


See http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-46183437

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜