I have a question. Im creating a website with a free editor. the website is http://pozzistore.com. The editor, because i'm using a free edition, allows me to have just 5 pages but i need more.
if you go on my website, on the homepage you will see different buttons that bring you to different pages and that is my question: instead of using 4 different pages, is there a way to use JavaScript to check wich button is pressed, open a new page and show a specific content?
i mean, this are two different pages of my website:
to access to this pages you have to click two different buttons. i want JavaScript to check the button pressed and open a new page and for example, if i press the first button on the new page, it shows http://pozzistore.com/P1.html and if i press the second button on the same page it shows http://pozzistore.com/P2.html.
I can not use PHP because i host the website with GitHub so i don't have an Apache Server
thank you
CodePudding user response:
You can use the open()
method.
<button onclick="openTab('myurl.com/path/to/the/first/page')">First page</button>
<button onclick="openTab('myurl.com/path/to/the/second/page')">Second page</button>
<button onclick="openTab('myurl.com/path/to/the/third/page')">Third page</button>
...
let tab=open();//that code open a new empty page at the begining, returns a `window` object (so you can use tab.alert(), tab.consloe.log() etc.)
function openTab(url) {
tab.location.href=url; //use the window.location object
}
CodePudding user response:
You can get Url and access to last part of it by below way:
for example if this is your url: http://pozzistore.com/P1.html
let url = window.location.href.split("/");
let page = url[url.length - 1];
if (page === "P1.html") {
...
} else if (...) { ... }