Skip to content
loading...

Is there any way to set the current URL to a blank URL in JavaScript?

twitter logo github logo ・1 min read  

So I am making an Undertale fan-game, and I disabled the "Inspect Element" feature almost completely, and I wanted to replace one if the bindings with a 'quit' feature. But if I set the URL to a blank string it will just reload the webpage, and

"."

doesn't work either. I tried seeing if their was a way to close the current window, which there wasn't. So, is there any way to set the current tab URL to be blank in JS? Also, thank you all, you all have filled me with determination (Alt Text) throughout my time here on this platform!
Thanks!
Cheers!

twitter logo DISCUSS (11)
markdown guide
 

So if I understand what your trying to do, you can simply prevent default behavior on the click event.
w3schools.com/jsref/event_preventd...

This will prevent the browser from redirecting to a new location and execute any code after preventDefault is called

 

No... What I wanted was a way for

location.assign()

to lead to a blank page, or a placeholder that webbrowsers would have built in or something...
CurrentPahe => New Tab

 

window.location.href = "about:home"; <-- this might get blocked depending on the users settings.
Also window.close() will close the tab but it can only be closed if the tab was created by your site.

Yes it’s part or the url scheme spec, works even in ie6

 

Hello!

What are you exactly trying to do? I couldn't totally understand. Also, are you using just javascript or more languages?

Maybe if you share the exact line of code that is giving you trouble the community will be able to help you :)

 

I am only using Javascript,
Issue: I want to set the tab to blank, as if you just opened a new tab in the browser

The solution(s) I've tried:

// solution 1 (doesn't work)
location.assign("")
// solution 2 (same)
location.assign("/")
// solution 3 (does absolutely nothing)
delete location.href

and so on, is there any way to make it so the current tab looks as if you opened a new tab in edge / chrome / etc...?

 

Try changing the href value to javascript:; or simply remove the href attribute completely.

 
Classic DEV Post from Feb 22

How do you avoid rabbit holes?

It's nice to go deep on a problem sometimes, but we can be tempted to go too deep. How do you manage...

PDS OWNER CALIN (Calin Baenen) profile image
I am a 13 (as of Oct 30 of 2019) yr/o developer (I have been developing mini-projects for 4, years now, since I was 9), who makes projects in languages like: Java, HTML, Python 3, JS, CSS, and C#.

DEV is visited by over 2 million software developers per month. You are welcome to publish here or simply read great content.

Get Started