---
title: "location.href=="
type: "forum-thread"
url: "https://www.webforum.nu/amne/javascript/139675-location-href"
topic: "JavaScript"
topic_url: "https://www.webforum.nu/amne/javascript"
author: "linux"
published: "2005-12-21T00:20:11.000Z"
updated: "2005-12-21T04:35:04.000Z"
replies: 1
views: 291
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/javascript/139675-location-href"
---

# location.href==

## #1 — linux, 2005-12-21T00:20Z

Hej!

Jag har all min javascript-kod i en fil som jag inkluderar på  alla mina html sidor. Men jag vill endast att funktion x ska  anropas om t.ex. sidan test.html laddas.

Jag har löst det genom att köra:
 

```
if (location.href=="test.html"){
     do this...
}
```

 osv...

Men är detta ett dumt eller konstigt sätt att lösa det på?
Jag har googlat lite men inte hitta något svar.

Permalänk: https://www.webforum.nu/p/139675

## #2 — linux, 2005-12-21T04:35Z

Jag byter ut location.href mot document.URL.

Permalänk: https://www.webforum.nu/p/1731346

---

Tråden på webben: https://www.webforum.nu/amne/javascript/139675-location-href
