4

I need a script that triggers a URL(go to the URL and that's it).

What's the shortest way to write this script?

2
  • 1
    Do you mean "takes the user to the URL in the browser", or "silently fires a GET request to the URL"? Commented Mar 21, 2011 at 4:02
  • Silently. That's why I said using Ajax. The user would stay on the same page while the browser fires a request to another page. The result from that request is ignored. Commented Mar 21, 2011 at 4:40

4 Answers 4

5

Use window.location.

window.location = 'http://stackoverflow.com';

Or shorter (not recommend though).

location = 'http://stackoverflow.com';

No ajaxical magic needed.

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

Comments

2
window.location='http://www.google.com';

Of course you could code-golf out the url and the semicolon.

Comments

1

Thanks: Use window.location.

window.location = 'http://stackoverflow.com';

1 Comment

Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
0

This is a sample AJAX code sample that can be used to fire a silent query to the browser and fetch the response and act on it.

var xmlhttp;

if (window.XMLHttpRequest)
    xmlhttp = new XMLHttpRequest();
else
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            // Do something with the result, like post a notification
        $('#notice').html('<p class="success">'+xmlhttp.responseText+'</p>');
    }
}

xmlhttp.open('GET',url, true);
xmlhttp.send();

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.