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?

1
  • A good word to search for more information on this topic is "bookmarklet". Commented Jul 26, 2011 at 1:21

5 Answers 5

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.

Sign up to request clarification or add additional context in comments.

5 Comments

more specifically you'd write javascript:window.open('http://www.google.com/');
What I am trying to do is have the function called on the page. I will give an example.
@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.
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.
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.
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>

Comments

0

Do you mean

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

This answer gives more detail.

Comments

0

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

Comments

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

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.