Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Your job is to open a browser window of the default browser to http://codegolf.stackexchange.com.

Edit: Your code must open the browser itself, and cannot rely on an open one.

This is , so the shortest answer in bytes wins.

share|improve this question

put on hold as unclear what you're asking by Mego, TimmyD, xnor, My Ham DJ, muddyfish 13 hours ago

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

3  
Are URL shorteners allowed? – isaacg yesterday
3  
Is it allowed to run JavaScript in the default browser to open a window? – Mwr247 yesterday
3  
@Mwr247 No, it is not. – CrazyPython yesterday
9  
You should add clarifications/restrictions to the question itself, since comments are not guaranteed to stick around forever. – Mego yesterday
5  
Your spec is minimal, which led to alot of uncertainty over what is allowed to accomplish the task. Additionally, some probably consider it a trivial task. Still, you're in the positive ;) – Mwr247 yesterday

31 Answers 31

Batch, 18 bytes

Saved 3 bytes thanks to Mego.

start www.ppcg.lol

This will open in your default browser if you run it from the windows command line.

I think it'll work in Powershell too, but I'm not sure.

share|improve this answer
    
You can use start instead of explorer. – Mego yesterday
5  
You can use start www.ppcg.lol instead to implicitly have Windows parse it as HTTP. Works in both CMD and PowerShell. – TimmyD yesterday
1  
1  
Why do you need the www.? – Blender yesterday
1  
@Blender Because otherwise it tries to find a local program called pccg with the .lol file extension and run it. – Morgan 'Venti' Thrappuccino yesterday

Oration, 42 bytes

Not winning, but sure was fun. :P I am almost beating python though, :D

I need webbrowser
Now open "http:ppcg.lol"

I need compiles to import $1 with webbrowser being the module.

Now runs the following command from the module as module.command with the arguments of anything following.

So this compiles to:

#!/usr/bin/env python3
import webbrowser
webbrowser.open("http:ppcg.lol")

I do end up needing the http:// part though, and it can't be shortened.

The code being the same as an earlier revision of @Skyler's answer is a coincidence.

This is the shortest possible Oration code, and I never saw the earlier revision for his answer. The only thing I did was upvote it when it had the "import *" part.

share|improve this answer
10  
As the owner of ppcg.lol, I approve of this message. – Quill yesterday
    
@Quill thankee for your url. :D It is actually shorter than all the normal url shorteners, btw. – Easterly Irk yesterday
    
This conversation has been moved to chat. – Dennis yesterday
    
I'm almost certain that you can replace "http://ppcg.lol" with "http:ppcg.lol". I'm uncertain whether you can remove the space between open and "http:...", but try it? – CoolestVeto yesterday
    
@CoolestVeto :D Can do the first trick, but the second one doesn't work. Oration needs the space. Thanks for the help. – Easterly Irk yesterday

PowerShell, 17 Bytes

saps www.ppcg.lol 

While start is a known alias for Start-Process there is another one for saps. You can see this from Get-Alias. It follows the convention for similar Start- and Stop- cmdlets.

share|improve this answer

Terminal (OSX), 20 18 bytes

open http:ppcg.lol

Saved 2 thanks to CoolestVeto

share|improve this answer
4  
open is an OSX utility, not a bash one; this would be more appropriately called "OSX command line". – Skyler yesterday
    
@Skyler Is this incorrect then? ss64.com/bash/open.html – Mwr247 yesterday
    
the first line: "Open a file in its default application, using virtual terminal (VT)." If you try to run that on unix, it will tell you "Couldn't get a file descriptor referring to the console", because it's trying to open in a terminal, not in a browser. – Skyler yesterday
2  
You can get rid of //. – CoolestVeto yesterday

MATLAB, 28 25 bytes

web www.ppcg.lol -browser
  • www is shorter than http:// and ensures that the address is processed as a URL
  • This is shorter using the implicit function call (which casts inputs as strings) rather than the explicit version web('www.ppcg.lol', '-browser').
  • If you are on a OS X, this can be simplified to web ppcg.lol -browser as MATLAB will automatically append an http:// (21 bytes)

Alternatives:

  • On windows this can be shortened to (19 bytes)

    !start www.ppcg.lol
    
  • On OS X (21 bytes)

    !open http://ppcg.lol
    
  • The following would work in a deployed MATLAB application (16 bytes)

    web www.ppcg.lol
    
  • If the built-in browser could be used this could be reduced even further as http is implied (12 bytes)

    web ppcg.lol
    
share|improve this answer
    
OS X is redundant because the built-in open command does the same. – CrazyPython yesterday
1  
@CrazyPython That's precisely what ! does in MATLAB, it's the equivalent of system(command). I had it as more of a demonstration of other alternatives that could be executed from within MATLAB. Is that OK? – Suever yesterday
    
Do you need the www.? – CoolestVeto yesterday
    
@CoolestVeto Sometimes you do sometimes you do not. When using the external browser you do, however the internal browser you do not. If you do not specify it, no browser window will open. If you can get it to work, I'm more than happy to change it! – Suever yesterday
    
@CoolestVeto So I dug a little more and it looks like the www is unnecessary only on OS X – Suever yesterday

 GNU Emacs, 29 27 15 bytes

(eww"ppcg.lol")

EWW is a browser inside Emacs. The browse-web function is an alias for eww, and so that makes eww the default browser in Emacs:

Your job is to open a browser window of the default browser to http://codegolf.stackexchange.com.

(thanks to CoolestVeto and Jonathan Leech-Pepin)

share|improve this answer
    
Can you use www.ppcg.lol instead of http://ppcg.lol? – TimmyD yesterday
1  
@TimmyD No, at first I tried with "www" but the protocol must be supplied (the behavior is different for example with "mailto://"). For user interaction, there is "browse-url-at-point" which prepends "http", but this is longer of course. – coredump yesterday
    
You shouldn't need the //, I don't think. (I don't use emacs, but it's generally accepted without the //) – CoolestVeto yesterday
    
@CoolestVeto Correct, thanks – coredump yesterday
    
Arguably this could be shortened to (eww"ppcg.lol") sinceeww is now the default browser for Emacs itself. (browse-web is an alias for eww in the menu bar) – Jonathan Leech-Pepin 17 hours ago

Bash, 24 22 bytes

xdg-open http:ppcg.lol

Not as short as some others. firefox ppcg.lol is shorter, but it doesn't meet question spec.

share|improve this answer
    
xdg-open www.ppcg.lol works for me as well. – Digital Trauma yesterday
    
@digital_trauma interesting, it didn't for me. It looked for www.ppcg.lol on the file system. Ubuntu 15.10. – Ogaday yesterday
    
Weird. Ubuntu 14.04 for me. xdg-utils 1.0. – Digital Trauma yesterday
1  
You shouldn't need the //. – CoolestVeto yesterday
1  
@CoolestVeto Correct. xdg-open http:ppcg.lol also works for me. – Digital Trauma yesterday

AutoHotKey, 16 bytes

Run www.ppcg.lol
share|improve this answer
3  
Unfortunately, not everybody has *shudder* Google Chrome *shudder* set as their default browser (or installed at all!). – wizzwizz4 yesterday
1  
Not everyone has AHK either...both facts are very shudder worthy – Michelfrancis Bustillos yesterday
2  
I was shuddering because I had to type... never mind. – wizzwizz4 yesterday
1  
The challenge spec requires opening PPCG in the default browser, which may or may not be Chrome. – Dennis yesterday
1  
You don't need the comma – Engineer Toast yesterday

Python, 52 48 47 45

Shamelessly borrowing that shortened link.

from webbrowser import*;open("http:ppcg.lol")

Thanks to CrazyPython for -4 bytes, and Sp3000 for a further one.

Edit: shaved 2 more off thanks to CoolestVeto

share|improve this answer
    
The former change leaves it exactly the same length. As for the http://, if you leave that out it tries to open a local file called "ppcg.lol", which doesn't exist. – Skyler yesterday
1  
You don't need //. – CoolestVeto yesterday
    
Thanks! I wonder why that works? – Skyler yesterday
    
I've always seen the // as convention, I don't think you need it for some browsers. – CoolestVeto yesterday
    
You can also do this with just command line options python -m webbrowser -t http:ppcg.lol which I think counts as 30 chars – gnibbler 23 hours ago

Java 7, 118 bytes

class P{public static void main(String[]a)throws Exception{java.awt.Desktop.getDesktop().browse(new java.net.URI("http://ppcg.lol"));}}

Java is not the best language for golfing... Here's the same program in a more readable format:

class P {
    public static void main (String[] a) throws Exception {
        java.awt.Desktop.getDesktop().browse(new java.new.URI("http://ppcg.lol"));
    }
}
share|improve this answer
7  
1  
@Mego I could do that, but then it would be Java 8. This is a Java 7 answer. But thanks for the tip! – Alex L. yesterday
    
Replace "http://ppcg.lol" with "http:ppcg.lol" – CoolestVeto yesterday
4  
code-golf specifies that functions are sufficient, you do not have to write a full program. So void f(){ .... } would be enough. – flawr yesterday
1  
Your program in more readable format is missing a closing parenthesis – Nate Kerkhofs yesterday

JavaScript, 34 bytes

require('open')('http://ppcg.lol')

Uses Node.js

share|improve this answer
    
Do you need //? – CoolestVeto yesterday
1  
If node.js supports ES6: require`open``http://ppcg.lol`; (added ; to avoid tripping the formatting) – Ismael Miguel 21 hours ago
    
Alternatively, does it require a protocol? eg require('open')('//ppcg.lol') to save 5 bytes – Martijn 18 hours ago
    
@Martijn Shh... – wizzwizz4 14 hours ago

R, 26 bytes

shell.exec("www.ppcg.lol")

I don't know of any shorter way to do this in R.

share|improve this answer
    
Duplicate of this. Simply wrapping another answer in a system/fork/whatever call is a trivial modification. – Mego yesterday

Racket, 41 bytes

(require net/sendurl)(send-url"ppcg.lol")
share|improve this answer

Java 8, 115 bytes

interface P{static void main(String[]a)throws Exception{java.awt.Desktop.getDesktop().browse(new java.net.URI("http://ppcg.lol"));}}

Java is not the best language for golfing... Here's the same program in a more readable format:

interface P {
    static void main (String[] a) throws Exception {
        java.awt.Desktop.getDesktop().browse(new java.net.URI("http://ppcg.lol"));
    }
}
share|improve this answer
    
You can remove the //. – CoolestVeto yesterday
    
Isn't it supposed to be java.net? – Ryan 16 hours ago
    
cant you replace interface with class? – MCMastery 14 hours ago
    
@MCMastery Yes. However, with an interface, you can save 3 bytes because even though interface is longer than class, you save more bytes because the public modifier is implied. – Alex L. 10 hours ago
    
@Ryan Whoops. Fail. Yes, you're right. Thanks! – Alex L. 10 hours ago

Mathematica, 28 bytes

SystemOpen@"http://ppcg.lol"
share|improve this answer
    
That would be 16 bytes in Mthmtca. – Michael Stern yesterday
    
Do you need //? – CoolestVeto yesterday
    
@CoolestVeto I think I do. – Martin Büttner yesterday
    
@MichaelStern Is that a thing? I want. – Mario Carneiro 17 hours ago
    
@MarioCarneiro A development version can be found at github.com/LegionMammal978/Mthmtca I don't have the system to make it work, but I'm counting on future releases being platform-agnostic. – Michael Stern 17 hours ago

Pylongolf, 11 bytes (Non-Competing)

"ppcg.lol"p

Pushes ppcg.lol into the stack then p opens it.

share|improve this answer
    
Will that open it as a local file, or as a website address? – wizzwizz4 yesterday
    
And did you just add the changes that allowed this to work? – Easterly Irk yesterday
    
@wizzwizz4 As an address. Yes, so this does not compete with others, just for fun. – Midnightas yesterday
2  
If I were you, I would edit "(Non-competing)" into the title, so people don't downvote. – wizzwizz4 yesterday
    
@wizzwizz4 done. – Easterly Irk 10 hours ago

Applescript, 28

  • 3 bytes saved thanks to @CoolestVeto.
open location"http:ppcg.lol"
share|improve this answer

Actionscript 3, 117 bytes

package{import flash.display.Sprite;public class A extends Sprite{function A(){navigateToUrl("ppcg.lol","_blank")}}}

Like Java, this is not a great golfing language. Here's the code with formatting:

package
{
    import flash.display.Sprite;

    public class A extends Sprite
    {
        function A()
        {
            navigateToUrl("ppcg.lol", "_blank")
        }
    }
}
share|improve this answer

C#, 33 bytes

Process.Start("http://ppcg.lol");

Opens the default browser to the web address

share|improve this answer
    
Nope... Replace \\ via //. – Qwertiy yesterday

VBScript, 57 bytes

I used to have lots of fun creating tiny programs in VBScript, back in 2010.

I've remembered this language and used the code on: http://stackoverflow.com/a/13401872/2729937

It still works on Windows 7, at least.

set S=CreateObject("WScript.Shell")
S.run("www.ppcg.lol")

This is a bit different from the usual start www.ppcg.lol, in the sense that it executes the www.ppcg.lol directly, with an implicit start.

An alternative way would be "cmd.exe /C start www.ppcg.lol".

share|improve this answer

Ruby, 22 20 bytes

`open http:ppcg.lol`

Simple.

Thanks to Daniel for 2 bytes off.

share|improve this answer
    
You can save 2 characters by using backticks instead of %x. open http:ppcg.lol – Daniel Evans 22 hours ago
    
@DanielEvans Great, thanks. That saves 2 bytes. – Easterly Irk 14 hours ago

VB.NET, 32 30 bytes

Process.Start("http:ppcg.lol")
share|improve this answer

Dyalog APL, 21 bytes

]Open http://ppcg.lol

Uses the User Command ]Open, which is installed with Dyalog.

share|improve this answer
    
Needs you the //? – CoolestVeto yesterday
    
@CoolestVeto Yes, otherwise you get an error: * Command Execution Failed: File not found – Nᴮᶻ yesterday

Factor, 38 36 bytes (noncompeting)

Don't know what leaving off wait-for-process does.

"xdg-open http:ppcg.lol" run-process

Only works on systems with Xorg / xdg-open such as any Linux, and Windows with MinGW. It'll work on Mac OSX if you install X.

I didn't know one could golf-off the // in the protocol.

I also didn't know this was a "copy" of the bash answer. Never mind...

share|improve this answer
    
I think you can remove the space between the end-quote and run-process, and you can wholly drop //. – CoolestVeto yesterday
    
@CoolestVeto Thanks! I didn't know the // could be left off. As for the space between " and run-process, dropping that would require a word named "run-process to be present in the current vocabulary search path – cat yesterday
    
@CoolestVeto Factor's like Forth -- highly whitespace dependent – cat yesterday
    
Duplicate of this. Simply wrapping another answer in a system/fork/whatever call is a trivial modification. – Mego yesterday
    
@Mego Okay, well, not that it really matters but I did come up with this without seeing that one. But, there is really no other way to run The default browser without xdg-open in languages which are not equipped with special functions for browsing the web. A C or ASM answer would surely also have to do system("xdg-open...") – cat yesterday

Perl 5, 66 bytes

Should work everywhere, but needs that import :(

use Browser::Open open_browser;open_browser("http://www.ppcg.lol")

Also, for funsies :

Perl 5 (Windows), 34 bytes

system "start http://www.ppcg.lol"

Perl 5 (Unix), 31 bytes

system "xdg-open http:ppcg.lol"
share|improve this answer

NodeJS, 53 bytes

require('child_process').exec('open http://ppcg.lol')

Works on mac.

share|improve this answer
    
Duplicate of this – Mego yesterday

05AB1E, 16 bytes (non-competing)

Non-competing, since the features used here postdate the challenge. Code:

’…Ò ™³.ÐÏg.´¢’.E

You can try the string online here. This basically evaluates to this batch answer.

Uses the CP1252 encoding.

share|improve this answer
    
How do you count the bytes? Depending which program I use for counting I get from 21 to 34 bytes. – sqlab 21 hours ago
    
@sqlab 05AB1E uses the CP1252 encoding. – A and N 21 hours ago

PHP, 33 bytes

<?php exec("open http:ppcg.lol");
share|improve this answer

R, 28 bytes

browseURL("http://ppcg.lol")

(in utils package)

share|improve this answer

Python, 43 41 bytes

import os
os.system("open http:ppcg.lol")

-2 bytes thanks to @Quill.

share|improve this answer
    
Duplicate of this – Mego yesterday
2  
@mego how is it a duplicate - It's not even the same language! – proud haskeller yesterday
    
@proudhaskeller See my comments on this answer – Mego yesterday
    
@mego on the nominations for moderator you said yo believe in hands-off moderation. I don't see how this is reflected here. – proud haskeller yesterday
    
@proudhaskeller By hands-off moderation, I mean letting the community do all the moderation work that it can, rather than stepping in with mod powers. As I am neither a moderator nor using moderation powers/privileges, this is still hands-off moderation. If you wish to discuss my views on moderation further, I would encourage you to do so with me in the chatroom created specifically for that purpose. – Mego yesterday

Not the answer you're looking for? Browse other questions tagged or ask your own question.