How to clear the address bar of Google Chrome?

I need to clear the address bar of Google Chrome when loading my extension page in a tab.

THIS is my extension, and the address to be cleared is as follows:

chrome-extension://<extension-id>/page.html
+4
source share
1 answer

* The real solution to your question is below.

Clear browser address bar

This is a pretty old question that occurred to almost everyone who has ever used JavaScript: can I replace the entire URL displayed in the address bar via JavaScript? Well, sorry, but the answer is a huge NOPE !

/ URL- ?

, JavaScript - , (Chrome, Mozilla, Opera...) API-. -, , . , - (, Facebook): , , , URL- "facebook.com/login", , Facebook ( , ?). , , .

JavaScript location history

JavaScript :

  • window.location, , (, .hostname, .path, .href ..) URL-. , .

    location.href = "http://newsite.com"; // will reolad
    location.path = "/home.html";         // will reload
    location.replace("google.com");       // will also reload
    
  • , , window.history, URL , (). .pushState() .replaceState() . , ( ).

    history.back();
    // will make your browser go back to the previous page
    
    history.pushState(null, null, "newPage.html");
    // will replace the current path with /newPage.html and add it to the history
    // http://example.com/page1.html -> becomes -> http://example.com/newPage.html
    // now, if you call history.back() the path will be set back to /page1.html  
    
    history.replaceState(null, null, "newPage.html");
    // will replace the current path with /newPage.html, PLUS it will also replace the current history path
    // http://example.com/page1.html -> becomes -> http://example.com/newPage.html
    // calling history.back() will not set the path back to /page1.html, but to the previous one (if exists)
    

    API . YouTube, Twitter URL- . , , (: Youtube , , ).

Chrome: URL

Google chrome , "chrome_url_overrides" manifest.json:

  • (chrome://newtab) .
  • (chrome://history), .
  • (chrome://bookmarks), .

, "" URL Chrome. , : Chrome - URL-, , . , , , URL- "chrome-extension://...".

  • "history" , URL- chrome://history.
  • "bookmarks" , URL- chrome://bookmarks.
  • "newtab" , URL- ().

, , ?

, , , <iframe> , JavaScript, src:

  • HTML:

    <iframe id="my-frame" style="width: 100%; height: 100%; margin: 0; padding: 0", frameborder="0"></iframe>
    
  • JavaScript:

    var frame = document.getElementById('my-frame');
    
    frame.src = "/path/to/page.html"; 
    // navigate to a local page stored in your extension
    
    // or:
    
    frame.src = "http://www.somesite.com";
    // navigate to an external site (not always possible)
    

: - . , , X-Frame-Options "SAMEORIGIN" (, google.com), , :

"Refused to display 'http://www.somesite.com/...' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'."

:

: "chrome_url_overrides" dashboard.html, script redirect.js, url: "/searchTab.html". URL- "chrome-extension://...". , , ?. , - searchTab.html... . . /dashboard.html manifest.json /searchTab.html:

...
"chrome_url_overrides": {
    "newtab": "/searchTab.html"
},
...
+6

All Articles