0

I am trying to call a function to open a lightbox when someone clicks a link that create. I have seen this done before but do not recall how something like:

google.com:javascript(openWindow())

does anyone know how I can do this?

jeffreynolte
  • 3,749
  • 11
  • 41
  • 64

5 Answers5

1
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.

Mike Samuel
  • 118,113
  • 30
  • 216
  • 245
  • more specifically you'd write `javascript:window.open('http://www.google.com/');` – zzzzBov Jul 26 '11 at 01:20
  • What I am trying to do is have the function called on the page. I will give an example. – jeffreynolte Jul 26 '11 at 01:22
  • @jnolte, When should the function be called? As the page loads or as a link or button is clicked? If the latter, then James McCormack has answered your question. – Mike Samuel Jul 26 '11 at 01:25
  • I am looking to call it when the page loads but via a parameter in the url. I want a lighbox function to open ONLY when the person clicks the link I provide. so essentially i am looking to pass the function into the url via a parameter. I am quite sure this is possible but do not know how. – jeffreynolte Jul 26 '11 at 04:08
  • You could encode the function using `encodeURIComponent()`, send it in the querystring, and then `eval()` it on the target page if the querystring parameter is detected. This does feel quite hacky though, and I don't recommend the approach. It would be better to just pass a querystring parameter to cause a function on the target page to run, possibly using the querystring parameter as an argument. – James McCormack Jul 26 '11 at 08:23
1

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>
Carls Jr.
  • 3,088
  • 7
  • 37
  • 57
0

Do you mean

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

This answer gives more detail.

Community
  • 1
  • 1
James McCormack
  • 9,217
  • 3
  • 47
  • 57
0

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

Pankaj Agarwal
  • 11,191
  • 12
  • 43
  • 59
0

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

}
Community
  • 1
  • 1
jeffreynolte
  • 3,749
  • 11
  • 41
  • 64