Bobby
Bobby

Reputation: 482

can I auto add hash tag into URL when the site is loaded?

I would like to know if there is any possible way to re-write a URL to include a hash tag when the site load?

Example:
www.google.com would automatically become www.google.com#something?

Thank you.

Upvotes: 2

Views: 2908

Answers (3)

GP cyborg
GP cyborg

Reputation: 198

This is an easy way to do it, correct me if i have mis-understood your question ! First use location.hash to add the "#something" to your URL Then redirect to the location using window.location in javascript. Try this snippet:

<html>
<head>
    <script type="text/javascript">
        location.hash = "something";
        window.location = location.hash;
    </script>
</head>
</html>

Upvotes: 0

Jacob T. Nielsen
Jacob T. Nielsen

Reputation: 2978

Yes you can do this.

location.hash = 'something';

Running this piece of code will add '#something' to the URL of said page.

Upvotes: 4

anishsane
anishsane

Reputation: 20980

If you want to AUTOMATICALLY redirect from www.google.com to www.google.com#something you can use firefox's redirector addon.
Whenever you load www.google.com, the addon will automatically change the URL in the location bar to www.google.com#something (or whatever you specify.)

Alternately, you could use firefox addon, called greasemonkey, to write the 1 line script given by Jacob. That will also serve the purpose.

Off course, both these solutions are specific to firefox.

Upvotes: 0

Related Questions