So I like to analyze websites and try to figure out how they work.
I came across this website.
http://us.battle.net/d3/en/forum/
They have a button that minimizes and maximizes divs. AND it remembers if you left it minimized or maximized, regardless if you're logged in or not. (it's browser specific, i.e. it only remembers based upon the brower you used.)
I see they're calling some javascript on this, but how is this done? Using cookies? I doubt it's being done with sessions since when I log in/out it doesn't affect it.
Thanks.
They are using the cookie forumParentToggle. This cookie is created the first time you expand or collapse a div.
For example, if you collapse the "Classes" div, the cookie is created with the value 3354995.
By deleting this cookie, the Classes div will be re-expanded when the page is refreshed. To the browser, it looks like you are visiting for the first time.
This cookie is referenced in the minified version of javascript they are utilizing here.
Related
I visit a site often that has a "click to change to dark theme" button. The dark theme is much easier to read, so I have to click the link every visit (history cleared on close).
I'm on a local Linux box with Firefox; so Javascript, HTML, Python and Bash are available.
I'm focused on a Bookmarklet as it seems like the right way - however, nothing I'm doing is working. I'm not versed in Javascript so it's been days looking up and trying examples. It may not be possible as a Bookmarklet, so perhaps there is another way around?
Bookmarklet - Set Then Go
Here's what I have:
javascript:document.cookie="theme=dark; domain=example.org; path=/;"; location.href="http://www.example.org";
It works if it's only the cookie, and it works if it only loads the site - but not both. I'm ok with programmatically going to the page first, setting the cookie, then reloading but that doesn't work either. I'm not wanting to click two links. "example.org" is how the cookie is stored for a normal visit, and I'm ok with the cookie only lasting for that session.
Persistent Cookie
I can't get Firefox (IceCat) to keep the cookie. I set it under Exceptions to allow, but nothing keeps it unless both "Keep cookies until they expire" and "Cookies" is unchecked for removal after close. Doing that keeps all cookies from everywhere which I'm not wanting to do.
Permanent Cookie
I'd tried setting the cookie in an immutable file - but Firefox doesn't keep cookies there anymore. They are in SQLite. Maybe there's a way to set a flag on the row so it's never removed? User.js and prefs.js don't seem to apply - but shouldn't it be possible to set the cookie in prefs.js or user.js that would set it for each browser load thereby creating a 'permanent cookie'?
Bookmarklet - Go Then Click
Another thing I tried was to open the page, then click the link programmatically to load the dark theme:
javascript:location.href="http://www.example.org";document.getelementbyid('Dark').click();
The ID is known and in the form of a non-valid anchor (no href). The site's javascript seems to be listening for a click event. Here is what they have:
$('#Dark').click(function(){
document.cookie='theme=dark; domain=.example.org; path=/';
window.location.reload(true);
});
So shouldn't it be as simple as setting an environment variable then loading the site - maybe JS doesn't have environment vars?
Inject It And Forget It
I read that it was possible to inject style into the head of the page, so I tried to inject:
<script>document.getelementbyid('Dark').click();</script>
via the Bookmarklet which seems like it should work as the click would be in a local context. I could never get it to inject, but again, I don't know Javascript.
Last Resort
If nothing above is possible, could it be done with bookmark to a local .html file that sets the cookie for the given domain then redirects to the site? A last ditch solution that is not preferred would be an actual script (.sh/.py)?
I don't want to share the site, and I don't want to not clear history on exit. Neither are due to what you're probably thinking. :)
I'm here because I'm wanting a Javascript solution (a bookmark), but I'm not good at Javascript - so all the examples above might work with tweaking, I'm just doing it wrong.
Thanks all for any help!! If you can fix it - could you also explain why what I had doesn't work?
Below is a try to explain rather than an answer.
Let's assume that you are already at the target page. Do the following bookmarklets work for you?
This:
javascript:(function() {
document.getElementById('Dark').click();
})();
or this one:
javascript:(function() {
document.cookie='theme=dark; domain=.example.org; path=/';
window.location.reload(true);
})();
I eventually figured out a cookie's initial entry can only be set by the domain, as a measure against XSS. So the answer to my question is it's not possible.
The simplest work around is to use an Add-On followed by userContent.css.
It would of been nice to set the theme preference (cookie) before loading the page - but I can see why the rule's in place..
It takes the same amount of clicks to go to the site and click "Change To Dark Theme" as it would if JS was used (open the site [1st click], set the cookie and reload [2nd click]).
Background:
I have a website that has multiple tabs running on server B. One of these tabs contains an iframe that is loading an Angularjs based site that is running on a separate server (server A). The site refreshes sections every 10 seconds to check for changes made elsewhere. When not on that tab, I want to block these calls. I need to find a way to detect whether the page is rendered and block the calls if it is not from within the server A.
Current solution:
In Firefox I have got this working using getBoundingClientRect().top on an element. The value changes when another tab is loaded so can check it and block the calls.
This doesn't work in Chrome though. The value doesn't change when swapping tabs.
Does anyone have any suggestions or experience with this? Need a solution that will work in all browsers.
Thank you for the suggestions.
Fixed this using:
parent.document.getElementsByTagName('iframe')[0].getBoundingClientRect().top
In all browsers this value changes when the iframe is no longer on the active page.
I want to store a specific value for each browser window.
This value should stay the same after a reload.
An example:
I want to open 2 tabs of my page, both of them should be able to show the data of two different accounts. E.g. gmail has the ability to swap between 2 logged in pages. And even if you refresh the tab, the visible account stays the same.
At the moment I have only one possible solution in mind:
Store the value in the url
Make sure that every link on this page pass this value to the next page
But this way seems to be a little bit "dirty". It gets broken if I miss a single link.
Is there a way to use a hidden input instead, or some other js features?
Btw: I'm using aspx and IIS as web server.
I think you should use cookie, they stored in browser and stay after reload.
Set cookie and get cookie with JavaScript
How can we hide the statusbar of a current page using javascript.I used window.statusbar.visible = false but its not working.Please give me a solution
regards
Arun
I don't think you can hide it for an already opened window : it's not an element of the page, but an element of the browser's user interface -- which means it's outside of your concern.
(Even if you can open a new window that doesn't have a status-bar ;; which might not be liked that much by some users, btw)
Status bars are something people expect to see in every browser window. By not hiding it, you give users the first sense of safety that the content they see is still being served within a browser. You may be trying to simulate a desktop application experience on the web. But once you code for the web, you have to happily accept the standard elements that come with it.
Technically, no, you cannot hide the status bar after opening the window.
I have a PHP and HTML based CMS. In each page of the CMS, there is a form with a Javascript-based tabbed dialog that switches between a number of DIVs.
From each page of the CMS, it is possible to open a preview page to see the changes made, and then return to the CMS. When the user returns, I would like the same tab page to be opened as when they left for the preview.
My current approach is to change the value of a cookie ("current_tab") each time the user changes a tab.
onclick='setCookie("current_tab", 5);'
When the tabbed dialog is generated, I check for the cookie and set the appropriate DIV to "display: block".
However, I need the cookie setting to be limited to that specific CMS page, and not all of them. If the user changes to a different page, the tab must not be pre-selected.
My current approach is to create a cookie for each page, e.g. for page ID 10254:
onclick='setCookie("current_tab_10254", 5);'
and, as an attempt of cleaning up, to remove that cookie when the page is rendered. But obviousy, this is not going to clean up every cookie that was set, because the user can choose not to return to the form, or navigate to a different page. I fear clutter through dozens of cookies in the system.
Does anybody have a better idea how to do this?
Try to Limit visibility of cookies by changing "path" parameter of cookie.
If structure of your application doesn't allow this, I'd suggest you not to use such approach, cause cookies are usually sent with every request, including requests to static information (images, css).
Why are you worried about removing the cookies? They will expire and remove themselves.