I have written a java class similar to default SendAsEmailActionExecuter. In this class a pdf file is modified. After successful execute of the doclib action alfresco does not refresh preview and keeps the old one until refresh the entire page. How can I tell to alfresco reload the document preview without the need to push F5?
I think if you simple want to refresh page using javascript there are number of ways to do that
window.location.reload(true);
or
window.location.reload();
or
location.href = location.href;
If you want to update metadata, There is a out of box api "metadatarefresh" of alfresco which you can use.Two ways to use that
Option 1:
In side your ajax call
this.modules.actions.genericAction(
{
success:
{
event:
{
name: "metadataRefresh"
},
.....
Option 2: Use it via bubbling
YAHOO.Bubbling.fire("metadataRefresh");
Hope this helps.
Related
I'm trying to build a button that will allow users to automatically opt into all of a developer's beta apps (or the ones they select from a list I'll present) without the need to navigate to each beta app's sign-up page on the google playstore. I've tried the following, it loads the page, but I can't get the button-click/form submit right when trying it through ajax.
$.ajax({
url: 'https://play.google.com/apps/testing/com.joaomgcd.autoshare',
success: function( data ) {
// process data (which is actually your page contents)
//console.log(data);
alert("Loaded");
//$("input.action").click();
//var clickme = document.querySelector(".action");
$('.joinForm').submit()
//clickme.click();
alert("Done");
}
});
I get the first popup, but not the second one. This particular developer has each link on one page of their website, I'm just trying to make it easier for his communities to opt into all betas instead of one-by-one. What am I doing wrong in my above code? Do I need to be clicking the input button titled "Become a Tester" (class input.action) or submitting the form that contains that input button (form class joinForm)?
Per request: Code of the Beta Opt-In page
Error being thrown:
When I am clicking back button from browser it is showing the outdated value from database. I tried to use following code but it's not working
<script type="text/javascript">
$(document).ready(function() {
alert("I am an alert box!");
});
</script>
How to refresh the page or get updated value when users click on back button of browser?
Asp.Net Webforms:
In Page Load (or) if you want all pages then put on Master Page Load
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
Asp.Net MVC:
Add this attribute in Action or Controller
[OutputCacheAttribute(VaryByParam = "*", Duration = 0, NoStore = true)]
Or
If you want disable cache for all views then add the below in Filter Config
filters.Add(new OutputCacheAttribute{VaryByParam = "*",Duration = 0,NoStore = true});
Edit: I noticed, in comment you mentioned you are using ruby on rail. I am not familiar with that, but the logic is server need to send an header to the browser for "do not cache that page". So you can find some answers here Ruby on Rails: Clear a cached page
Use a hash to determine if it has already been refreshed, to ensure it happens just once:
window.onload = function() {
if(!window.location.hash) {
window.location = window.location + '#loaded';
window.location.reload();
}
}
There is no problem with the integration of jquery and the code. Rails project comes with TurboLink which have some conflicts with jquery. One of the possible solution is to remove turbolink from the project (remove it from application.rb) and use Jquery-Turbolink.
This will allow to use jquery inbuilt functions like I had in my question.
Please update the answer or add comment for other possible solutions.
So I have a web page with some photos of people. When you click on a photo of the person the JavaScript is executed and produces a popup with some more detailed information such as a description etc.
The link for each photo is as follows:
First I want to start with the basics, of just extracting the description etc. from one single person. So I want to execute the JavaScript above to write the popup window, and when I'm on the popup window I can then extract the content of the div's on the popup.
I've looked at PhantomJS and I really don't know where to start. I've used Cheerio to get some simple information from the page, and I want to move on to executing the popup window through JS and then extracting data from that.
Any help would be appreciated as I'm a bit of a newbie to screen scraping in general.
You can do this analogous to how CasperJS does it.
page.open(yourUrl, function(success){
// mainPage is loaded, so every next page could be a popup
page.onPageCreated = function onPageCreated(popupPage) {
popupPage.onLoadFinished = function onLoadFinished() {
popupPage.evaluate(function(){
// do something in popup page context like extracting data
});
};
};
// click to trigger the popup
page.evaluate(function(){
document.querySelector("a.seeMore").click();
// or something from here: http://stackoverflow.com/questions/15739263/phantomjs-click-an-element
});
});
Do not forget to overwrite/nullify page.onPageCreated before navigating away from the main page.
I am using ajax post requests for doing paging on a feed in my site. When getting the post request data I am reforming the page by clearing previous data and rendering the new data that came from the request. I want to be able to change the URL as well so saving the new page link will get the user to the current page.
Example:
User on page example.com/feed - seeing content of page #1
User clicking to get to page #2 -> ajax post is send and data on the page is changed using js (no refresh)
URL is still example.com/feed but the content is of example.com/feed?page=2
How can I set the URL to point to the new page without triggering a refresh (no redirect) ?
I am using Nodejs + express.
I understand you are aiming at a single page application.
While keeping the url is nice, note you might want distinct urls for directly accessing different parts of your application. Still, you can load content with AJAX and keep a smooth application. The way to go is using the hash part of the location.
The Sammy.js framework gives you a nice base to build upon, you can try it out.
You can use history pushstate but some browsers does not support.
history.pushState({id: 'SOME ID'}, '', 'myurl.html');
And don't forget about window.onpopstate, it pops if user clicks back button.
Redirect the user to an anchor point.
Page 2
And in your document.ready:
if (window.location.hash.length > 1){
var pageNumber = window.location.hash.substring(1);
loadPage(parseInt(pageNumber));
} else{
loadPage(0);
}
I don't believe it is possible to change the query part of the URL without triggering a refresh (probably due to security issues). However you may change the anchor and use an event listener to detect when the anchor is being changed.
//Listener
$(window).on('hashchange', function() {
if(loaction.hash.length > 1) {
//The anchor has been changed.
loadPageWithAjax("example.com/feed.php?page=" + location.hash.substring(1));
} else {
//Load standard page
...
}
});
Change the anchor to load new feed
Page 2
Remember to not use an anchor that is used as an id, since this makes the browser scroll to that element.
I need to detect the first time a page loads in jQuery so that I can perform some actions only when the page loads the first time a user navigates to that page. Similar to server side code page.ispostbasck. I have tested $(document).ready and it fires every time the page loads so this will not provide what I need. I have also tried the jQuery Load function - it also fires every page load. So by page load an example is that I have an HTML input tag on the page of type button and it does not fire a postback (like an asp.net button) but it does reload the page and fires $(document).ready
Thanks
You will have to use cookie to store first load information:
if (! $.cookie("cookieName")){
// do your stuff
// set cookie now
$.cookie("cookieName", "firstSet", {"expires" : 7})
}
Note: Above example uses jQuery Cookie plugin.
An event doesn't exist that fires only when the page is loaded for the first time.
You should use jQuery's .ready() event, and then persist the fact that you've handled a first time page load using your method of choice (i.e. cookie, session variable, local storage, etc.).
Note: This method will never be fool proof unless you can store this information at the user level in a DB. Otherwise, as soon as the user clears their cookies, or whatever method you choose, the "first time loaded" code will fire again.
I just ran into this problem and this is how I handled it. Keep track of the first time the page loads by using a variable initialLoad:
var initialLoad = true;
$(document).ready(function() {
...
...
...
initialLoad = false;
});
Then in other functions, you can do this:
if (initialLoad) {
//Do work that is done when the page was first refreshed/loaded.
} else {
//Do work when it's not the initial load.
}
This works well for me. If the user is already on the page and some jQuery functions run, I now know if that user just loaded the page or if they were already on the page.
The easy solution is to use jQuery ‘Once’ plugin
$(element).once('class-name', function() {
// your javascript code
});