打开浏览器到http://codegolf.stackexchange.com


33

您的工作是将默认浏览器的浏览器窗口打开到http://codegolf.stackexchange.com

您的代码必须打开浏览器本身,并且不能依赖于打开的浏览器。

这是,因此最短的答案以字节为单位。


8
是否允许使用URL缩短器?
isaacg '16

4
是否可以在默认浏览器中运行JavaScript来打开窗口?
Mwr247 '16

4
@ Mwr247不,不是。
noɥʇʎԀʎzɐɹƆ

15
您应该在问题本身上添加澄清/限制,因为不能保证注释会永远存在。
Mego

8
您的规格是最小的,这导致在允许完成任务的内容上存在很多不确定性。此外,有些人可能认为这是一项琐碎的任务。不过,您还是很积极的;)
Mwr247 '16

Answers:


35

 GNU Emacs, 29 27 14字节

(eww"ppcg.ga")

EWW是Emacs中的浏览器。该browse-web功能是一个别名eww,而这样就使得eww默认浏览器在Emacs:

您的工作是将默认浏览器的浏览器窗口打开到http://codegolf.stackexchange.com

感谢@ CoolestVeto,@ Jonathan Leech-Pepin和@ zyabin101。


可以www.ppcg.lol代替使用http://ppcg.lol吗?
AdmBorkBork'Mar

1
@TimmyD不,起初我尝试使用“ www”,但是必须提供协议(例如,“ mailto://”的行为是不同的)。对于用户交互,有一个“浏览URL-point-point”在“ http”的前面,但这当然更长。
coredump

//我不认为您不需要。(我不使用emacs,但通常不使用emacs //
Addison Crump

11
ಠ_ಠPPCG并不是要“ ewwww”的东西,那是代码审查:P
Downgoat 16-4-12

3
显然有ppcg.ga。它可以为您节省一个字节。
user48538 '16

46

Oration,41个字节

没有赢,但是肯定很有趣。截至目前,我仅比python落后1个!

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

说明:

I need编译成import $1webbrowser作为模块。

Now从模块运行以下命令,以及module.command随后的任何参数。

因此,将其编译为:

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

我最终还是需要http:一部分,并且不能缩短它。


17
作为ppcg.lol的所有者,我批准此消息。
Quill

此对话已转移至聊天
丹尼斯

我几乎可以确定您可以将替换"http://ppcg.lol""http:ppcg.lol"。我不确定是否可以删除空格之间open"http:...",但试试吗?
Addison Crump

2
@Quill我的意思是我们怎么知道您在将来的某个时候Rick不会把我们全部推翻?
PyRulez '16

1
@Quill取决于您对Rick的喜欢程度
TMH

43

批次,17个字节

多亏了Mego,节省了3个字节。

start www.ppcg.ga

如果从Windows命令行运行它,它将在默认浏览器中打开。

我认为它也可以在Powershell中使用,但是我不确定。


3
您可以使用start代替explorer
Mego

8
您可以start www.ppcg.lol改为使用Windows隐式地将其解析为HTTP。在CMD和PowerShell中均可使用。
AdmBorkBork'Mar

2
为什么需要www.
Blender 2016年

3
@Blender因为否则它会尝试找到带有.lol文件扩展名的本地程序pccg并运行它。
Morgan Thrapp

2
@PyRulez从技术上讲,它不是URL缩短器。Quill不久前购买了该域,并设置了DNS重定向。
Mego

24

PowerShell,17个16字节

saps www.ppcg.lol 

使用Milo提供的甚至更短的域。

saps www.ppcg.ga

虽然start是已知的别名,Start-Process但还有一个别名saps。您可以从查看Get-Alias。它遵循类似Start-Stop-cmdlet 的约定。


psst,您现在可以使用www.ppcg.ga
Milo

@Milo谢谢。我想其他人可以听到你的声音。
马特

ppcg.ga无法正常工作
-anukul

2
嗯 仍然为我工作,我将假定milo。也许是新的,DNS还没有完全将会传播
马特

21

终端(OSX),20 18 17字节

open http:ppcg.ga

由于CoolestVeto节省了2


5
open是OSX实用程序,不是bash实用程序;这将更合适地称为“ OSX命令行”。
斯凯勒

1
@Skyler这是不正确的吗?ss64.com/bash/open.html
Mwr247 '16

1
第一行:“使用虚拟终端(VT)在其默认应用程序中打开文件。” 如果您尝试在Unix上运行它,它将告诉您“无法获得引用控制台的文件描述符”,因为它试图在终端而不是浏览器中打开。
斯凯勒

3
您可以摆脱//
Addison Crump

2
您可以保存另一个字节:open http:ppcg.ga
DarkDust

14

MATLAB,28 25字节

web www.ppcg.lol -browser
  • www短于http://并确保将地址作为URL处理
  • 使用隐式函数调用(将输入转换为字符串)比显式版本要短一些web('www.ppcg.lol', '-browser')
  • 如果您使用的是OS X,则可以简化web ppcg.lol -browser为MATLAB会自动附加一个http://21个字节

替代方案

  • 在Windows上,可以缩短为(19个字节

    !start www.ppcg.lol
    
  • 在OS X上(21字节

    !open http://ppcg.lol
    
  • 以下内容将在已部署的MATLAB应用程序中工作(16个字节

    web www.ppcg.lol
    
  • 如果可以使用内置浏览器,则可以进一步减少http隐含含义(12个字节

    web ppcg.lol
    

OS X是冗余的,因为内置open命令执行相同的操作。
noɥʇʎԀʎzɐɹƆ

1
@CrazyPython正是!在MATLAB中执行的操作,等效于system(command)。我将其作为可以在MATLAB内执行的其他替代方案的更多示例。这可以吗?
Suever 2016年

您需要www.吗?
Addison Crump

@CoolestVeto有时您有时不这样做。使用外部浏览器时,您可以,但是不使用内部浏览器。如果未指定,则不会打开浏览器窗口。如果您可以使用它,我很乐意对其进行更改!
Suever 2016年

@CoolestVeto所以我挖了一点,看来www只有在OS X上才不需要
Suever

13

AutoHotKey,16个字节

Run www.ppcg.lol

7
不幸的是,并非所有人都将* shudder * Google Chrome * shudder *设置为其默认浏览器(或完全安装了该浏览器!)。
wizzwizz4 2016年

5
也不是每个人都有AHK ...两个事实都非常值得颤抖
Michelfrancis Bustillos

5
我发抖,因为我不得不打字...没关系。
wizzwizz4 2016年

2
挑战规范要求在默认浏览器(可能为Chrome)中打开PPCG 。
丹尼斯

1
您不需要逗号
Engineer Toast

13

蟒蛇,52 48 47 45 44字节

无耻地借用了缩短的链接。

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

多亏了CrazyPython提供了-4个字节,而Sp3000又提供了一个。

编辑:多亏了CoolestVeto,剃了2折

编辑:感谢MD XF注册ppcg.ga并保存另一个字节


前一个更改使它的长度完全相同。至于http://,如果忽略它,它会尝试打开一个名为“ ppcg.lol”的本地文件,该文件不存在。
斯凯勒

1
您不需要//
Addison Crump

谢谢!我不知道为什么行得通?
斯凯勒

1
您也可以仅使用命令行选项python -m webbrowser -t http:ppcg.lol来完成此操作,我认为这可以算作30个字符
gnibbler

1
ppcg.lol已被取消注册,使该答案无效:I但是,我刚刚注册了ppcg.ga,因此您可以改用它,无论如何保存一个字节。
MD XF

10

Bash,24 22字节

xdg-open http:ppcg.lol

不像其他的那么短。firefox ppcg.lol较短,但不符合问题规范。


xdg-open www.ppcg.lol也为我工作。
Digital Trauma

@digital_trauma有趣,对我而言不是。它在文件系统上寻找www.ppcg.lol。Ubuntu 15.10。
Ogaday

奇怪的。对我来说是Ubuntu 14.04。xdg-utils 1.0。
Digital Trauma

1
您不需要//
Addison Crump

1
@CoolestVeto正确。 xdg-open http:ppcg.lol也对我有用。
Digital Trauma'Mar

10

Java 7, 118 115 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.net.URI("http:ppcg.ga"));
    }
}

Saved 2 bytes by removing // in the URI/L, and another byte by switching to .ga from .lol (indirectly thanks to @Milo)



1
@Mego I could do that, but then it would be Java 8. This is a Java 7 answer. But thanks for the tip!
HyperNeutrino

1
Replace "http://ppcg.lol" with "http:ppcg.lol"
Addison Crump

8
code-golf specifies that functions are sufficient, you do not have to write a full program. So void f(){ .... } would be enough.
flawr

1
Your program in more readable format is missing a closing parenthesis
Nzall

9

Pylongolf, 11 bytes (Non-Competing)

"ppcg.lol"p

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


Will that open it as a local file, or as a website address?
wizzwizz4

And did you just add the changes that allowed this to work?
Rɪᴋᴇʀ

@wizzwizz4 As an address. Yes, so this does not compete with others, just for fun.

5
If I were you, I would edit "(Non-competing)" into the title, so people don't downvote.
wizzwizz4

@wizzwizz4 done.
Rɪᴋᴇʀ

9

Java 8, 115 112 bytes

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

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.ga"));
    }
}

Saved 2 bytes by removing // (thanks @CoolestVeto), and another byte by switching to .ga from .lol (indirect thanks to @Milo)


You can remove the //.
Addison Crump

Isn't it supposed to be java.net?
Ryan

cant you replace interface with class?
MCMastery

@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.
HyperNeutrino

@Ryan Whoops. Fail. Yes, you're right. Thanks!
HyperNeutrino

8

JavaScript, 34 bytes

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

Uses Node.js


Do you need //?
Addison Crump

2
If node.js supports ES6: require`open``http://ppcg.lol`; (added ; to avoid tripping the formatting)
Ismael Miguel

2
Alternatively, does it require a protocol? eg require('open')('//ppcg.lol') to save 5 bytes
Martijn

2
@Martijn Shh...
wizzwizz4

ppcg.lol has been unregistered, invalidating this answer :I However, I just registered ppcg.ga, so you can use that instead, saving a byte anyway.
MD XF

7

Racket, 41 40 bytes

(require net/sendurl)(send-url"ppcg.ga")

ppcg.lol has been unregistered, invalidating this answer :I However, I just registered ppcg.ga, so you can use that instead, saving a byte anyway.
MD XF

Thanks for commenting. I'll update my answer in front of a computer later today. :)
Winny

6

Applescript, 28 bytes

  • 3 bytes saved thanks to @CoolestVeto.
open location"http:ppcg.lol"

how dare a high-rep user not format their header correctly D:
cat

1
@cat actually, I've never been called out on this before - I've always operated on the assumption that bytes is the default for codegolf (and is even explicitly specified in this question), so explicitly respecifying in answers is just redundant information. Do you know of a meta post about this?
Digital Trauma

Well, first and foremost, my comment was messing around -- I only changed it for consistency with all the other answers, and it's really insignificant but it bothered me. I'm pretty sure there's no meta post on formatting specifically, and that this format came from the Leaderboard Stack Snippets, but I'm almost certain there's a meta post for Defaults for Scoring Code Golf that says it's bytes unless otherwise specified.
cat

1
@cat Yep, I don't think its a big deal either way - I'm certainly not planning on rolling back your edit :). Scoring by bytes by default is in the code-golf tag wiki
Digital Trauma

ppcg.lol has been unregistered, invalidating this answer :I However, I just registered ppcg.ga, so you can use that instead, saving a byte anyway.
MD XF


5

R, 26 bytes

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

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


1
Duplicate of this. Simply wrapping another answer in a system/fork/whatever call is a trivial modification.
Mego

ppcg.lol has been unregistered, invalidating this answer :I However, I just registered ppcg.ga, so you can use that instead, saving a byte anyway.
MD XF

5

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")
        }
    }
}

ppcg.lol has been unregistered, invalidating this answer :I However, I just registered ppcg.ga, so you can use that instead, saving a byte anyway.
MD XF

5

Rebol 2, 16 15 bytes

browse"ppcg.ga" 

if you accept an error before opening the page on Linux, no error on Windows

20 bytes without an error

browse http:ppcg.lol

Alternative to the first one (although with the same score): browse #ppcg.lol
Izkata

now with shorter url.(
sqlab

5

Perl 5, 66 57 bytes

Should work everywhere, but needs that import :(

8 bytes saved with @msh210 comment.

use Browser::Open open_browser;open_browser"http:ppcg.ga"

Also, for funsies :

Perl 5 (Windows), 34 bytes

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

Perl 5 (Unix), 31 bytes

system "xdg-open http:ppcg.ga"

use -M instead of use to shave a coupla bytes. (Untested.) Also, I'm guessing you don't need the parens or the www.. (Also untested.)
msh210

@msh210 Can't seem to get the -M switch to work apparently on my Mac... (?), but indeed the www as well as the // can be removed. Thanks !
Paul Picard

ppcg.lol has been unregistered, invalidating this answer :I However, I just registered ppcg.ga, so you can use that instead, saving a byte anyway.
MD XF

Edit done. Thank you for keeping old answers up to date :)
Paul Picard


3

RFO-BASIC, 22 bytes

BROWSE "http:ppcg.lol"

Read about RFO-BASIC at laughton.com.


While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
Mego

Alright. I just figured most people wouldn't know about this "dialect" of BASIC.
TickTock

ppcg.lol has been unregistered, invalidating this answer :I However, I just registered ppcg.ga, so you can use that instead, saving a byte anyway. Also, couldn't the space between BROWSE and " be removed, saving another byte?
MD XF

3

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: https://stackoverflow.com/a/13401872/2729937

It still works on Windows 7, at least.

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

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

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


ppcg.lol has been unregistered, invalidating this answer :I However, I just registered ppcg.ga, so you can use that instead, saving a byte anyway.
MD XF

@MDXF Thank you for that tip. While it is nice to save a byte, I won't change the score since it doesn't feel fair.
Ismael Miguel

2

C#, 33 bytes

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

Opens the default browser to the web address


Nope... Replace \\ via //.
Qwertiy

not a c# program, just a single line
BryanJ

Also this needs the System.Diagnostics namespace to be added in or Process to be fully qualified to work.
TheLethalCoder

1
This is not a c# program.
Vahid Amiri

ppcg.lol has been unregistered, invalidating this answer :I However, I just registered ppcg.ga, so you can use that instead, saving a byte anyway.
MD XF

2

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.


How do you count the bytes? Depending which program I use for counting I get from 21 to 34 bytes.
sqlab

@sqlab 05AB1E uses the CP1252 encoding.
Adnan

2

VB.NET, 32 30 bytes

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

+10 for Sub Main(), and +7 for End Sub, which you need in order to run this at least in a VB.NET console program, also you would need to import System.Diagnostics.
Virtual Anomaly

ppcg.lol has been unregistered, invalidating this answer :I However, I just registered ppcg.ga, so you can use that instead, saving a byte anyway.
MD XF

2

Factor, 38 36 26 bytes

[ "http:ppcg.ga" open-url ]

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


I think you can remove the space between the end-quote and run-process, and you can wholly drop //.
Addison Crump

@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

@CoolestVeto Factor's like Forth -- highly whitespace dependent
cat

Duplicate of this. Simply wrapping another answer in a system/fork/whatever call is a trivial modification.
Mego

@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

2

Python, 44 bytes

from webbrowser import*;open('http:ppcg.ga')

URL from this comment
Edit: ppcg.ga seems to become more popular now (but it WAS available when I posted this answer).

Ungolfed:

from webbrowser import * # Loads everything in the webbrowser module
open("http://ppcg.ga/") # Opens default browser to http://ppcg.ga/

Python, 44 bytes

from webbrowser import*;open('http:gfa1.tk')

URL from this answer

Ungolfed:

from webbrowser import * # Loads everything in the webbrowser module
open("http://gfa1.tk/") # Opens default browser to http://gfa1.tk/

Python, 45 bytes

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

Ungolfed:

from webbrowser import * # Loads everything in the webbrowser module
open('http://ppcg.lol/') # Opens default browser to http://ppcg.lol/

Take that, ppcg.lol! (1 byte shorter)

Note: I added a separate answer leading to ppcg.lol, 'cause I've noticed the other sites doesn't work for me in Internet explorer 11, and I saw other users having this problem too.

Both are non-non-competing (read that right?)


2

Ruby, 22 20 19 bytes (on OS X)

`open http:ppcg.ga`

Simple.

Thanks to Daniel for 2 bytes off.


You can save 2 characters by using backticks instead of %x. open http:ppcg.lol
Daniel Evans

@DanielEvans Great, thanks. That saves 2 bytes.
Rɪᴋᴇʀ

1
"'open' is not recognized as an internal or external command, operable program or batch file."
Dewi Morgan

1
@DewiMorgan OS X only.
Rɪᴋᴇʀ

2

Cheddar, 65 bytes

cheddar.internal(cheddar.uid).require("open").c("http://ppcg.ga")

Accesses cheddar internals and then calls upon open package and calls it with string to PPCG. Make sure you have open npm package installed


Shouldn't this be Cheddar+Open if it requires another package?
Pavel
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.