1 /*
2 * Copyright (c) 2002-2025 Gargoyle Software Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 * https://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 package org.htmlunit.javascript.host.event;
16
17 import org.htmlunit.corejs.javascript.ScriptableObject;
18 import org.htmlunit.javascript.JavaScriptEngine;
19 import org.htmlunit.javascript.configuration.JsxClass;
20 import org.htmlunit.javascript.configuration.JsxConstructor;
21 import org.htmlunit.javascript.configuration.JsxGetter;
22
23 /**
24 * JavaScript object representing the HashChangeEvent.
25 * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/window.onhashchange">Mozilla Developer Network</a>
26 * @see <a href="http://msdn.microsoft.com/en-us/library/cc288209.aspx">MSDN</a>
27 *
28 * @author Ronald Brill
29 * @author Marc Guillemot
30 * @author Frank Danek
31 */
32 @JsxClass
33 public class HashChangeEvent extends Event {
34
35 private String oldURL_ = "";
36 private String newURL_ = "";
37
38 /**
39 * Creates a new event instance.
40 */
41 public HashChangeEvent() {
42 super("");
43 }
44
45 /**
46 * Creates a new event instance.
47 *
48 * @param target the event target
49 * @param type the event type
50 * @param oldURL the old URL
51 * @param newURL the new URL
52 */
53 public HashChangeEvent(final EventTarget target, final String type,
54 final String oldURL, final String newURL) {
55 super(target, type);
56 oldURL_ = oldURL;
57 newURL_ = newURL;
58
59 setBubbles(false);
60 setCancelable(false);
61 }
62
63 /**
64 * {@inheritDoc}
65 */
66 @Override
67 @JsxConstructor
68 public void jsConstructor(final String type, final ScriptableObject details) {
69 super.jsConstructor(type, details);
70
71 String oldURL = "";
72 String newURL = "";
73 if (details != null && !JavaScriptEngine.isUndefined(details)) {
74 oldURL = (String) details.get("oldURL");
75 newURL = (String) details.get("newURL");
76 }
77 oldURL_ = oldURL;
78 newURL_ = newURL;
79 }
80
81 /**
82 * Returns the old URL.
83 * @return the old URL
84 */
85 @JsxGetter
86 public String getOldURL() {
87 return oldURL_;
88 }
89
90 /**
91 * Returns the new URL.
92 * @return the new URL
93 */
94 @JsxGetter
95 public String getNewURL() {
96 return newURL_;
97 }
98 }