How to get the page URL by location-element?
Answer: by defining following attributes:slice
to one of values provided bellowsrc
optionally with URL, If omitted, it would match thewindow.location.href
slice
to one of values provided bellowsrc
optionally with URL, If omitted, it would match the window.location.href
<a href="#dce2">#dce2</a>
<form method="get">
<input name="p1" value="abc">
<input name="p2" value="def">
<input type="submit" value="params">
</form>
<button onclick="history.pushState( {},'', 'location-element.html?pushstate')">history.pushState</button>
<button onclick="history.replaceState( {},'', 'location-element.html?replaceState#dce1')">history.replaceState</button>
Has to produce URL properties
<custom-element tag="dce-2" hidden="">
<template>
<location-element slice="window-url" live="" method="" src=""></location-element>
<xhtml:table>
<xhtml:tbody>
<xhtml:tr>
<xhtml:th><h3> URL properties </h3></xhtml:th>
<xhtml:td>{count(//value/@*)}</xhtml:td>
</xhtml:tr>
<apply-templates mode="attrs" select="//value/@*"></apply-templates>
</xhtml:tbody>
</xhtml:table>
<xhtml:table>
<h3> URL parameters </h3>
<apply-templates mode="attrs" select="//params/*/*"></apply-templates>
</xhtml:table>
<xsl:template mode="attrs" match="*|@*">
<xhtml:tr>
<xhtml:th>{name()}</xhtml:th>
<xhtml:td>{.}</xhtml:td>
</xhtml:tr>
</xsl:template>
</template>
</custom-element>
<dce-2>?</dce-2>
URL properties |
9 |
---|---|
href | https://unpkg.com/@epa-wg/custom-element@0.0.33/demo/location-element.html |
origin | https://unpkg.com |
protocol | https: |
host | unpkg.com |
hostname | unpkg.com |
port | |
pathname | /@epa-wg/custom-element@0.0.33/demo/location-element.html |
search | |
hash |
Has to produce URL properties
<custom-element tag="dce-1" hidden="">
<template>
<location-element slice="window-url"></location-element>
<xhtml:table>
<xhtml:tbody>
<xhtml:tr><xhtml:th><h3>URL properties</h3></xhtml:th></xhtml:tr>
<for-each select="//slice/window-url/value/@*">
<xhtml:tr>
<xhtml:th>{name()}</xhtml:th>
<xhtml:td>{.}</xhtml:td>
</xhtml:tr>
</for-each>
</xhtml:tbody>
<xhtml:tbody>
<xhtml:tr><xhtml:th><h3>URL parameters</h3></xhtml:th></xhtml:tr>
<for-each select="//slice/window-url/value/params/*">
<xhtml:tr>
<xhtml:th>{name()}</xhtml:th>
<xhtml:td>{.}</xhtml:td>
</xhtml:tr>
</for-each>
</xhtml:tbody>
</xhtml:table>
</template>
</custom-element>
<dce-1>?</dce-1>
URL properties | |
---|---|
href | https://unpkg.com/@epa-wg/custom-element@0.0.33/demo/location-element.html |
origin | https://unpkg.com |
protocol | https: |
host | unpkg.com |
hostname | unpkg.com |
port | |
pathname | /@epa-wg/custom-element@0.0.33/demo/location-element.html |
search | |
hash | |
URL parameters |
Has to produce URL properties
<custom-element tag="dce-3" hidden="">
<template>
<location-element slice="href-url" href="https://my.example?a=1&b=2#3"></location-element>
<xhtml:table>
<xhtml:tbody>
<xhtml:tr><xhtml:th><h3>URL properties</h3></xhtml:th></xhtml:tr>
<for-each select="//slice/href-url/value/@*">
<xhtml:tr>
<xhtml:th>{name()}</xhtml:th>
<xhtml:td>{.}</xhtml:td>
</xhtml:tr>
</for-each>
</xhtml:tbody>
<xhtml:tbody>
<xhtml:tr><xhtml:th><h3>URL parameters</h3></xhtml:th></xhtml:tr>
<for-each select="//slice/href-url/value/params/*">
<xhtml:tr>
<xhtml:th>{name()}</xhtml:th>
<xhtml:td>{.}</xhtml:td>
</xhtml:tr>
</for-each>
</xhtml:tbody>
</xhtml:table>
</template>
</custom-element>
<dce-3>?</dce-3>
URL properties | |
---|---|
origin | https://my.example |
protocol | https: |
username | |
password | |
host | my.example |
hostname | my.example |
port | |
pathname | / |
search | ?a=1&b=2 |
hash | #3 |
href | https://my.example/?a=1&b=2#3 |
URL parameters | |
array | 1 |
array | 2 |