开发者

How to pass a function to a url in javascript

开发者 https://www.devze.com 2023-03-23 00:52 出处:网络
I am trying to call a function to open a lightbox when someone clicks a link that create.I have 开发者_如何学JAVAseen this done before but do not recall how something like:

I am trying to call a function to open a lightbox when someone clicks a link that create. I have 开发者_如何学JAVAseen this done before but do not recall how something like:

google.com:javascript(openWindow())

does anyone know how I can do this?


javascript:openWindow()

is a URL that most browsers interpret as invoking the openWindow() function and treating the result coerced to a string as the result of loading the URL.

See HTML5 6.1.5 The javascript: URL scheme for more detail.


you might be referring to this

<html>
<body>
    <script type="text/javascript">
        function clickMe(){
            //your code here to call lightbox and etc.
            alert('test');
        }
    </script>

    <a href="javascript:clickMe()">click</a>
</body>
</html>


Do you mean

<a href="#" onclick="yourOpenLightboxFunction(); return false;" />

This answer gives more detail.


I think it can be BookMark, you can bookmark to quickly run JavaScript functions from your address bar.


The following code ended up being what helped me to complete the task. I found the answer here

var url = document.location.href;
if(url.search(/\?lightbox/i) !== -1){
    //run function here

}
0

精彩评论

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