[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Is this possible?
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 16
Thread images: 2
File: FRONTPAGE.png (3 KB, 586x326) Image search: [Google]
FRONTPAGE.png
3 KB, 586x326
Is this doable?

Let's say i have a website, with two graphical buttons. If i click on them it will change the content on a subpage. The content is simple text, something like "button1=1, button2=0".
Now here comes the hard part:

the subsite should have no html tags and other bullshit like that, it should just act kinda like a txt file.

Is this possible?
>>
Here's an example what i mean by subsite:
frontpage: retardssite.com
subpage: retardssite.com/content
>>
File: retard.png (73 KB, 1279x778) Image search: [Google]
retard.png
73 KB, 1279x778
This is basically how the subsite would look like:
>>
what you have described is AngularJS

yes it is doable
>>
>>51560489
How do i into AngularJS?

I know some programming languages like C but i know pretty much nothing about web development other than entry level noob html tags.
>>
The easiest is just to use cookies.
>>
Like that?

https://elements.polymer-project.org/bower_components/neon-animation/demo/card/index.html
?

What exactly do you mean? Do you just want to display a different page without reloading or do you actually want to load some text/plain content to replace your current site?
>>
You're asking about a way to set browser state based on a button press.

You can use cookies or localStorage.


Really simple example. Braces may not be aligned properly.

<button>Button1</button><button>Button2</button>
<script>
document.querySelectorAll(".button").onclick = function() { localStorage.setItem($(this).text(), "1"); };
// with jQuery it'd be $(".button").click(...)
</script>


Second page:

<script>document.write("button1 = " + localStorage.button1 + ";" + "button2 = " + localStorage.button2);</script>
>>
>>51561163
It is an IOT thing, where a device checks periodically the content of the subsite, and it would be easy to process simple text data.
Real computers and browsers are not even playing here.
I just want to change the text on the subsite depending on the button cliks of the frontpage.
>>
>>51561295
Also the button elements should have class="button". Forgot to add that.
>>
>>51561295
>
querySelectorAll(".button").onclick


Umm... You came from jquery, huh? This will only work for the first button. querySelectorAll returns a nodeList, which is one of the most useless containers ever. You'll have to iterate over it to assign the onclick handler to all the buttons, sadly.
>>
>>51561309
If it's not an actual browser doing it, you're going to have to use a database and backend.

In your backend application, you can route "/status.txt" or whatever to some code that queries the database, and on the main page, you'll update the rows based on something you pass in the URL, probably the query string. Why did you mention buttons if there will be no button clicking?

>>51561347
Yeah I initially wrote it with jQuery then changed it. I forgot the native DOM API is still shit.
>>
>>51561309

Use node.js with express
>>
>>51561295
So that's what he meant?

Then he could do something like

(page one)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<button type="button" class="saveButton" id="one">Button one</button>
<button type="button" class="saveButton" id="two">Button two</button>
<hr>
<button type="button" id="reset">Reset</button>
<script>
var buttons = document.getElementsByClassName("saveButton");
for(var i = 0, length = buttons.length; i < length; ++i)
{
buttons[i].addEventListener('click', function () {
localStorage.setItem(this.id, true);
});
}

document.getElementById('reset').addEventListener('click', function () {
for(var i = 0, length = buttons.length; i < length; ++i)
{
localStorage.setItem(buttons[i].id, false);
}
});
</script>
</body>

</html>

(page two)

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<p>Clicked the first button: <span id="one">IDK</span></p>
<p>Clicked the second button: <span id="two">IDK</span></p>
<script>
document.getElementById('one').textContent = localStorage.one;
document.getElementById('two').textContent = localStorage.two;

window.addEventListener('storage', function (event) {
document.getElementById(event.key).textContent = event.newValue;
});
</script>
</body>
</html>


And holy fuck, the native API sucks dicks. No wonder everyone uses jquery.
By the way, localstorage obviously only works on pages of the same domain. You can't just open these HTML files in your browser, you'll need to host them on a server of some kind (use python's if you have it installed or some xampp).
>>
>>51561754
>database
>instantly says python
Use MySQL OP
>>
>>51561463
>node.js
you mean get 15 modules to get one one functional website only to have one module update, and break your website for weeks on end? Or have express upgrade again? Have you tried searching for express tutorials? Most are in express 3. Express 4 is out

tldr;
npm suck a dick
Thread replies: 16
Thread images: 2

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.