JavaScript Back Button Failure - javascript

So I thought this script was pretty straight forward:
<a id="BackButtonlnk" href="#" class="white" onClick="history.go(-1)"></a>
When I click it it briefly shows the previous page but just looks like it refreshes
and you never end up at the previous page.

Try adding "; return false" to your onclick.
I think what's happening is the onclick fires (trying to go to the previous page), and then the browser tries to go to "(current page)#" (note the "#"), and essentially refreshes the original page. Thus, it appears that it's going back and forth - because it is.
<a id="BackButtonlnk" href="#" class="white" onClick="history.go(-1); return false;"></a>

Try using the href instead of the onclick event:
<a id="BackButtonlnk" class="white" href="javascript:history.go(-1);">Go Back</a>

In Javascript has many forms.
<a id="BackButtonlnk" class="white" href="javascript:history.back(-1);">Go Back</a>
If you wanna do that you write, recomend
<a id="BackButtonlnk" class="white" href="javascript:history.go(-1);"></a>

Related

How to keep submenu opened after page load in JavaScript

I have almost done my work and my client ask for keeping submenu opened when user click the item in the menu and also set active color. The idea is better orientation when user actualy is. In React App it wouldn't be problem, cuz whole app works like single page. In this case i've decided use only HTML/JS as my challenge.
Is it even possible somehow keep menu opened/open again menu when new page is loaded please?
I tried make from this app something like single page app by some tutorials like "load paghe without refresh" etc, but nothing worked.
menu
<div class="menu">
<div class="item">
<a class="sub-btn">
Matice
<i class="fas fa-angle-right dropdown"></i>
</a>
<div class="sub-menu">
<a
href="/pages/matice/zakladni-operace.html"
id="matice/zakladni-operace"
onClick="reply_click(this.id)"
class="sub-item">
Základní operace
</a>
<a
href="/pages/matice/hodnosti.html"
id="matice/hodnosti"
onClick="reply_click(this.id)"
class="sub-item">
Hodnost
</a>
<a
href="/pages/matice/determinanty.html"
id="matice/determinanty"
onClick="reply_click(this.id)"
class="sub-item">
Determinanty
</a>
<a
href="/pages/matice/inverzni-matice.html"
id="matice/inverzni-matice"
onClick="reply_click(this.id)"
class="sub-item">
Inverzní matice
</a>
<a
href="/pages/matice/maticove-rovnice.html"
id="matice/maticove-rovnice"
onClick="reply_click(this.id)"
class="sub-item">
Maticové rovnice
</a>
<a
href="/pages/matice/vlastni-cisla-a-vektory.html"
id="matice/vlastni-cisla-a-vektory"
onClick="reply_click(this.id)"
class="sub-item">
Vlastní čísla a vektory
</a>
</div>
</div>
</div>
You can try to get window.location.href on load of your page and add style classes depending on conditionally with something like
<div class="<%= 'yourStyleClass' if #url== 'urURL' %>"> to set active color
You could use AJAX to call the page. But that doesn't sound like what you want. An alternative way in javascript would be to get the current window.location.href when the page loads, then inject a class name into the relevant node, and have the css for that class make it visible and highlighted.
If you're using a library like jQuery this shouldn't be too hard to achieve.

JavaScript- Click a certain button on a webpage

Here's a webpage : http://www.mirakee.com/milind_ek_kavi
Now this webpage contains around 1000's of post by this user, and I wish to like all of them at once.
Each post contains a like button.
Now i want a script(bot type) that would click all the like buttons at once. and all of them get registered(accepted).
Please do tell me where and how to embed the script.
Thanks a lot.
UPDATE:
This is the HTML code for the like button:
<div>
<span class="like_content post_zy2v7yjilw_like">
<a class="like-post" data-remote="true" data-method="post" rel="nofollow noopener" href="/posts/zy2v7yjilw/like">
<span class="heart"></span>
</a>
<a class="likes-count" rel="nofollow noopener" data-remote="true" href="/posts/zy2v7yjilw/likes">
46
</a> </span>
<span class="comment-icon"></span>
<span class="comment-count">1</span>
<span class="reposts-icon"></span>
<a class="comment-count" rel="nofollow noopener" data-remote="true" href="/posts/zy2v7yjilw/reposts">
4
</a> </div>
You can use this
$(".like-post").trigger("click");
The main problem will be that it will trigger click only for elements which are actually available on page. I mean that the posts which are not loaded yet will have no effect of this code.
So, either you can first load all the posts by scrolling manually or you need to write script for that too.
Use jQuery's click() function.
$(element).click();
But may be abusing a feature like that is illegal. I currently don't have access to your DOM on mobile, so you can add your own query instead of element

Html > Redirect to a new Page and Refresh the Main Page where the Button is

I create a Button using HTML and CSS with this Code
<article>
<span class="image">
<img src="images/test.jpg" alt="" />
</span>
<header class="major">
<h3><a href="#" class="link" >Test</a></h3>
<p>Test</p>
</header>
</article>
I want the following to happen when you click this Button:
A new link opens in a new Tab (I know that you can do this with target="_blank" and when you go to the new tab, the page where this button is gets reloaded / refreshed.
I tried a few things with JavaScript but nothing worked.
Here is what I tried:
<h3><a href="#" onclick="window.open('http://www.yahoo.com', '_blank')();window.location.href=window.location.href();" class="link" >Teamspeak</a></h3>
<h3>Test</h3>
Because href is not a function. No need of parenthesis. In your javascript code href is used as href().
Please remove the extra pair of parenthesis after window.open function also.
Call a javascript function from <a onclick="javascript:fn ()" >load </a>.
From that function, open this url and do window.location.reload () to reload current page.

I have a button that when clicks it opens the link in the same page

I need the code to make it a pop-up in a different window.
Here is the code that is there if you could please tell me what code needs to be added that would help
<p>
<a class="btn"
onclick="link"
href="http://sizechartcms.finntack.com/?cat=competition&id=32086&lang=en_US">
Size Chart
</a>
</p>
Add target=_blank to open a new window:
<a target=_blank class="btn" href="http://sizechartcms.finntack.com/?cat=competition&id=32086&lang=en_US">Size Chart</a>
And remove onclick="link"
If you want something to show up in a new tab, you need to add target="_blank" into the a tag like so:
<a target="_blank">

jQuery: jqPlot function call won't work properly

I am basically wondering why this first code works but not the 2nd.
<a data-role="button" href="#page2" type="button" onClick="drawChart([[["Test1",6],["Test2",5],["Test3",2]]])">
<img src="icons/page2.png" inline style="height:80px"/><br/>Tilbakemelding
</a>
The above code does NOT work.
Within page2 I made a button with the following code:
<div data-role="content">
<a type="button" onClick=drawChart([[["Test1",6],["Test2",5],["Test3",2]]])>Show Chart</a>
</div>
This code works, but I would really prefer to have the chart up without having to do that extra click. This is coded in jQueryMobile so the first button does not only load the chart but also navigates to page2.
It is a syntax error; your "s are all off. Try:
onClick="drawChart([[['Test1',6],['Test2',5],['Test3',2]]])"

Categories

Resources