Разрешено ли запускать JavaScript в браузере по умолчанию, чтобы открыть окно?
Mwr247
4
@Mwr247 No, it is not.
noɥʇʎԀʎzɐɹƆ
15
You should add clarifications/restrictions to the question itself, since comments are not guaranteed to stick around forever.
Mego
8
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
Ответы:
35
GNU Emacs, 2927 14 bytes
(eww"ppcg.ga")
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:
Can you use www.ppcg.lol instead of http://ppcg.lol?
AdmBorkBork
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
You shouldn't need the //, I don't think. (I don't use emacs, but it's generally accepted without the //)
Addison Crump
11
ಠ_ಠ PPCG is not something to "ewwww" that, that's code review :P
Downgoat
3
Apparently there is ppcg.ga. It may save you a byte.
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?
Addison Crump
2
@Quill I meant how do we know you won't Rick roll us all at some future point?
PyRulez
1
@Quill that depends on how much you like Rick...
TMH
43
Batch, 17 bytes
Saved 3 bytes thanks to Mego.
start www.ppcg.ga
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.
You can use start www.ppcg.lol instead to implicitly have Windows parse it as HTTP. Works in both CMD and PowerShell.
AdmBorkBork
2
Why do you need the www.?
Blender
3
@Blender Because otherwise it tries to find a local program called pccg with the .lol file extension and run it.
Morgan Thrapp
2
@PyRulez It's not a URL shortener, technically. Quill bought that domain a while back and set up a DNS redirect.
Mego
24
PowerShell, 17 16 Bytes
saps www.ppcg.lol
Using an even shorter domain provided by Milo.
saps www.ppcg.ga
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.
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
3
You can get rid of //.
Addison Crump
2
You can save another byte: open http:ppcg.ga
DarkDust
14
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)
OS X is redundant because the built-in open command does the same.
noɥʇʎԀʎzɐɹƆ
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
Do you need the www.?
Addison Crump
@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
@CoolestVeto So I dug a little more and it looks like the www is unnecessary only on OS X
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
1
You don't need //.
Addison Crump
Thanks! I wonder why that works?
Skyler
1
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
1
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
10
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.
@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.
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.
@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.
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.
+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, 3836 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/
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.
Ответы:
GNU Emacs,
292714 bytesEWW is a browser inside Emacs. The
browse-web
function is an alias foreww
, and so that makeseww
the default browser in Emacs:Thanks to @CoolestVeto, @Jonathan Leech-Pepin and @zyabin101.
источник
www.ppcg.lol
instead ofhttp://ppcg.lol
?//
, I don't think. (I don't use emacs, but it's generally accepted without the//
)Oration, 41 bytes
Not winning, but sure was fun. As of right now, I'm only 1 bytee behind python!
Explanation:
I need
compiles toimport $1
withwebbrowser
being the module.Now
runs the following command from the module asmodule.command
with the arguments of anything following.So this compiles to:
I do end up needing the
http:
part though, and it can't be shortened.источник
"http://ppcg.lol"
with"http:ppcg.lol"
. I'm uncertain whether you can remove the space betweenopen
and"http:..."
, but try it?Batch, 17 bytes
Saved 3 bytes thanks to Mego.
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.
источник
start
instead ofexplorer
.start www.ppcg.lol
instead to implicitly have Windows parse it as HTTP. Works in both CMD and PowerShell.www.
?PowerShell,
1716 BytesUsing an even shorter domain provided by Milo.
While
start
is a known alias forStart-Process
there is another one forsaps
. You can see this fromGet-Alias
. It follows the convention for similarStart-
andStop-
cmdlets.источник
Terminal (OSX),
201817 bytesSaved 2 thanks to CoolestVeto
источник
open
is an OSX utility, not a bash one; this would be more appropriately called "OSX command line".//
.open http:ppcg.ga
MATLAB,
2825 byteswww
is shorter thanhttp://
and ensures that the address is processed as a URLweb('www.ppcg.lol', '-browser')
.web ppcg.lol -browser
as MATLAB will automatically append anhttp://
(21 bytes)Alternatives:
On windows this can be shortened to (19 bytes)
On OS X (21 bytes)
The following would work in a deployed MATLAB application (16 bytes)
If the built-in browser could be used this could be reduced even further as
http
is implied (12 bytes)источник
open
command does the same.!
does in MATLAB, it's the equivalent ofsystem(command)
. I had it as more of a demonstration of other alternatives that could be executed from within MATLAB. Is that OK?www.
?www
is unnecessary only on OS XAutoHotKey, 16 bytes
источник
Python,
5248474544 bytesShamelessly borrowing that shortened link.
Thanks to CrazyPython for -4 bytes, and Sp3000 for a further one.
Edit: shaved 2 more off thanks to CoolestVeto
Edit: thanks to MD XF for registering ppcg.ga and saving another byte
источник
//
.python -m webbrowser -t http:ppcg.lol
which I think counts as 30 charsppcg.lol
has been unregistered, invalidating this answer :I However, I just registeredppcg.ga
, so you can use that instead, saving a byte anyway.Bash,
2422 bytesNot as short as some others.
firefox ppcg.lol
is shorter, but it doesn't meet question spec.источник
xdg-open www.ppcg.lol
works for me as well.//
.xdg-open http:ppcg.lol
also works for me.Java 7,
118115 bytesJava is not the best language for golfing... Here's the same program in a more readable format:
Saved 2 bytes by removing
//
in the URI/L, and another byte by switching to.ga
from.lol
(indirectly thanks to @Milo)источник
"http://ppcg.lol"
with"http:ppcg.lol"
void f(){ .... }
would be enough.Pylongolf, 11 bytes (Non-Competing)
Pushes ppcg.lol into the stack then
p
opens it.источник
Java 8,
115112 bytesJava is not the best language for golfing... Here's the same program in a more readable format:
Saved 2 bytes by removing
//
(thanks @CoolestVeto), and another byte by switching to.ga
from.lol
(indirect thanks to @Milo)источник
//
.interface
is longer thanclass
, you save more bytes because thepublic
modifier is implied.JavaScript, 34 bytes
Uses Node.js
источник
//
?require`open``http://ppcg.lol`;
(added;
to avoid tripping the formatting)require('open')('//ppcg.lol')
to save 5 bytesppcg.lol
has been unregistered, invalidating this answer :I However, I just registeredppcg.ga
, so you can use that instead, saving a byte anyway.Racket,
4140 bytesисточник
ppcg.lol
has been unregistered, invalidating this answer :I However, I just registeredppcg.ga
, so you can use that instead, saving a byte anyway.Applescript, 28 bytes
источник
ppcg.lol
has been unregistered, invalidating this answer :I However, I just registeredppcg.ga
, so you can use that instead, saving a byte anyway.Mathematica, 28 bytes
источник
//
?R, 26 bytes
shell.exec("www.ppcg.lol")
I don't know of any shorter way to do this in R.
источник
system
/fork
/whatever call is a trivial modification.ppcg.lol
has been unregistered, invalidating this answer :I However, I just registeredppcg.ga
, so you can use that instead, saving a byte anyway.Actionscript 3, 117 bytes
Like Java, this is not a great golfing language. Here's the code with formatting:
источник
ppcg.lol
has been unregistered, invalidating this answer :I However, I just registeredppcg.ga
, so you can use that instead, saving a byte anyway.Rebol 2,
1615 bytesif you accept an error before opening the page on Linux, no error on Windows
20 bytes without an error
источник
browse #ppcg.lol
Perl 5,
6657 bytesShould work everywhere, but needs that import :(
8 bytes saved with @msh210 comment.
Also, for funsies :
Perl 5 (Windows), 34 bytes
Perl 5 (Unix), 31 bytes
источник
-M
instead ofuse
to shave a coupla bytes. (Untested.) Also, I'm guessing you don't need the parens or thewww.
. (Also untested.)ppcg.lol
has been unregistered, invalidating this answer :I However, I just registeredppcg.ga
, so you can use that instead, saving a byte anyway.Common Lisp, 31 bytes
источник
RFO-BASIC, 22 bytes
Read about RFO-BASIC at laughton.com.
источник
ppcg.lol
has been unregistered, invalidating this answer :I However, I just registeredppcg.ga
, so you can use that instead, saving a byte anyway. Also, couldn't the space betweenBROWSE
and"
be removed, saving another byte?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.
This is a bit different from the usual
start www.ppcg.lol
, in the sense that it executes thewww.ppcg.ga
directly, with an implicitstart
.An alternative way would be
"cmd.exe /C start www.ppcg.ga"
.источник
ppcg.lol
has been unregistered, invalidating this answer :I However, I just registeredppcg.ga
, so you can use that instead, saving a byte anyway.C#, 33 bytes
Opens the default browser to the web address
источник
\\
via//
.System.Diagnostics
namespace to be added in orProcess
to be fully qualified to work.ppcg.lol
has been unregistered, invalidating this answer :I However, I just registeredppcg.ga
, so you can use that instead, saving a byte anyway.05AB1E, 16 bytes (non-competing)
Non-competing, since the features used here postdate the challenge. Code:
You can try the string online here. This basically evaluates to this batch answer.
Uses the CP1252 encoding.
источник
VB.NET,
3230 bytesисточник
Sub Main()
, and +7 forEnd Sub
, which you need in order to run this at least in a VB.NET console program, also you would need to importSystem.Diagnostics
.ppcg.lol
has been unregistered, invalidating this answer :I However, I just registeredppcg.ga
, so you can use that instead, saving a byte anyway.Factor,
383626 bytesI didn't know one could golf-off the
//
in the protocol.источник
run-process
, and you can wholly drop//
.//
could be left off. As for the space between"
andrun-process
, dropping that would require a word named"run-process
to be present in the current vocabulary search pathsystem
/fork
/whatever call is a trivial modification.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 dosystem("xdg-open...")
Python, 44 bytes
URL from this commentEdit: ppcg.ga seems to become more popular now (but it WAS available when I posted this answer).
Ungolfed:
Python, 44 bytes
URL from this answer
Ungolfed:
Python, 45 bytes
Ungolfed:
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?)
источник
Ruby,
222019 bytes (on OS X)Simple.
Thanks to Daniel for 2 bytes off.
источник
%x
.open http:ppcg.lol
Cheddar, 65 bytes
Accesses cheddar internals and then calls upon
open
package and calls it with string to PPCG. Make sure you haveopen
npm package installedисточник