I am trying to create an anchor in order to be able to build such an URL :
www.mysite.com/#myAnchor
which should automatically link to the div wanted, even from an exterior website.
However, when I am trying to implement it, here is the adresse to which I am redirected : www.mysite.com/#/myAnchor
So far, I tested different things such as :
<a name="myAnchor" />
<a name="#myAnchor"></a>
<a name="myAnchor"></a>
<span class="anchor " id="myAnchor"></span>
But nothing seems to work.
However when I am on the page I can change the url to go there but from "outside" this just redirects to the top of the page.
Thanks for your help.
That most likely happens because the first anchor is done by the browser, and when the page loads for the first time I assume the content is not all loaded yet (using views?).
If that is the case, then you need to call the service $anchorScroll that angular provides somewhere in your code after the view has been loaded (on a ng-init maybe?). Something like
<a name="myAnchor" ng-init="loadScrollToAnchor()"></a>
And then in your controller, after injecting the service $anchorScroll.
var scrolled = true;
$scope.loadScrollToAnchor = function () {
if ( !scrolled ) {
$anchorScroll();
scrolled = true;
}
};
Update: The scrolled variable is there to make sure that the code is only executed once (at page load), and thus this code should reside in an application-wise controller and not a controller specific to a route or view. However, there are still some shortcomings to this approach that might need to be countered, like if the view that the user loads the page first has no ng-init calling the function, and then he moves to another view that does: the code will execute, and the user viewport will possibly be changed against the user's intents.
To solve it, I actually only had to add this line of code without anything else :
This is doing the trick.
Related
I have a SideMenu page fragment in my app. On each and every page, I have a copy of this page fragment.
My intention was to create a SideMenu with openable SubMenus (only one sub menu could be open at a time), but I could not get it done to make the app "remember" the state of the SideMenu( like which SubMenu should be open, and which ones shouldn't), because on each site there is a different widget, so when in my code ( in my onClick events) I refer to the widget, I am not handling "a global SideMenu" but rather a specific copy of it, unique to that page.
Sadly, this took several hours of debugging to realize, I am defeated.
Is there anyway to place a page fragment on a page, so I can handle that widget on its own, not just it's copies?
Thanks in advance, I can try to specify more the question if it's needed.
I agree with #MarkusMalessa. You need to invoke the widget on every page and then apply whatever change on it. I am doing the samething on a project in which I intend to shrink and expand the sideMenu. To give you an idea, evertime I click a button on the side menu responsible for the logic, this is the code that's invoked:
var pages = app.pages._values;
pages.forEach(function(page){
var sideMenu = page.descendants.sideMenu1;
if(sideMenu){
if(widget.text === "chevron_right"){
sideMenu.getElement().style.width = "300px";
} else {
sideMenu.getElement().style.width = "60px";
}
}
});
That way every sideMenu widget inside each page that has it receive the same changes.
Right now, I have 2 separate pages and I want to be able to click something on one page that makes an image in a div tag visible on the other page.
This is how i made my div tag invisible.
On the other page, I have an image that is clickable, and i want it to make the div visible. Help please?
You'd need to set up some kind of web socket. When the image is clicked you'd fire off an ajax request which stores a flag in a database. The other page would be listening for that flag and when it changed the image would become visible/invisible.
Check this out
The simplest way to do so would be to set a cookie (or store the state in browser local storage, but that is not available everywhere) when you click your button, and have the other page poll for it.
Server-side solutions like sockets or session variables look like A-bombs swatting flies here, but that would surely improve your cool factor by a few thousand points.
This seems like a pretty weird design in the first place, but surely you have your reasons...
If the first page triggers the second page to open you could use javascripts window.open() and pass in what to display
<!DOCTYPE html>
<html>
<body>
<p>Click the button to open a new window called "MsgWindow" with some text.</p>
<button onclick="myFunction()">Open window</button>
<script>
function myFunction() {
var myWindow = window.open("", "MsgWindow", "width=600, height=300");
myWindow.document.write("<p>This is 'MsgWindow'. I am 600px wide and 300px tall!</p><div> <img src='http://www.jyte.com/wp-content/uploads/2013/11/google-hummingbird.jpg' alt='nothing' /> </div>");
}
</script>
</body>
</html>
the best option would be using a web app using controllers, views, modules and services like angular where the first page controller can update the service and the second page controller would have the service injected so when the service changes it updates the scope which in turn updates the view.
other options would be using backend databases and ajax to store the click and having the second page check very second for update in the database and then update the page, but this method is really not practical (running an ajax request every second).
another option is using the browsers local storage, (not supported in all browsers) here is a link
local storage.
I'm starting to learn Windows 8.1 phone development and I am trying to get the Content Dialog template to work inside a Pivot page. Work some reason, when I try to get the Add app bar button to navigate to the ContentDialog.xaml page, it is not displaying, but I see the navigate go to the ContentDialog constructor where the this.InitializeComponent() occurs.
I am finding very little online in way of examples on this template, so I am at a loss as to what I am missing. I understand that the ContentDialog page that was created from the template is inheriting from ContentDialog and not Page, but I'm not sure if this is still supposed to be directly accessed or if this XAML is supposed to be inside another "Page" XAML file.
Can someone please help.
The code looks like this in the Pivot page when the click event is selected:
Frame.Navigate(typeof(ContentDialog1));
I really haven't even touched the ContentDialog template from it's default yet, so it is set up like a set password page.
Thanks in advance
UPDATE
I found the answer to my question above. apparently, because it is a Content control, it needs to be called like a normal dialog would need to be called in it's code behind. I think my missconseption was that I thought it being "a template", that when I called it with the navigation calls that it would already have everything needed to get fired. You can also add the Content control to an existing page if you would like.
In either scenario, you need to add a method similar to this in your XAML.CS file.
private async void OpenDialog()
{
await this.contentStuff.ShowAsync();
}
You then need to call this method in the constructor. Then, when called, your dialog will appear.
Hope this helps others just starting out.
I´m tryin` to start a html-file always on a defined id.
I know that´s possible if you use that:
go to...
But this happens only if this link was clicked.
How can i force it all the time?
To start on a defined anchor (hash-defined) you will need to use JavaScript. The hash anchor in the end of a URL is used by the browser just after the navigation completes and you can't force it to "auto"-move without any client-side code.
To achieve similar effect with javascript perform the following function when the page is loaded:
function jumpToId( id ){
location.hash = "#" + id;
}
Of course, you will need to supply the id you want to jump to as the parameter to this function.
Please note, that in case JavaScript is disabled in the client's browser, the scrolling will not be performed. It is not a big deal, however, because majority of users have JavaScript enabled all the time (especially in today's social network-driven world :-) ).
Do you want it to scroll to the area or just immediately pop the user to it? For scroll you could use jQuery and just set it to scroll to the div using $(document).ready().
Here is an example. If you just want them to pop to it you could change the 1000 to 1 and it appears to immediately pop to the div.
Example Here Using jQuery
I am starting my internship on a Home Server able to control mutliple domotics equipments from a web page. The global idea is that based on a click on a button, a certain script is spawned on the server and controls a microcontroller.
My tutor built a simple website he gave me, using AJAX to always stay on 1 page, and brings the menus according to user actions (they are hidden if not used, brought back to front if used).
I have set up an apache server which I configured to execute CGI scripts, and it works.
To always stay on one page, I used the '204 No Content' return trick, so that the server's answer to the page is 'I don't have anything to say, just stay on this page'.
But the one problem I have is that the CGI is launched only once. If I click the button for the first time it works, afterwards nothing happens.
I tried using the SSI (shtml) to use the in a button code instead of using a FORM with GET method but the script still won't execute twice.
I might be using the wrong tools. Should I keep going with CGIs ? Or is there something else (like AJAX, jquery) that actually is designed to do what I want ?
Thanks for having read.
EDIT : I have found a way around it (it's always when I'm desperate after looking for days for an answer that I go to forums and then find myself a nice solution in the next hour .... )
I used a basic link, and for some reason it has a different behaviour than using a button. Whatever. My interrogations on the technologies used still stand though :)
EDIT2 : My solution is crappy, for some reason the script is also called at page refresh (or when the page loads for the first time). It's strange, because since it's in the it should only be spawned when I click on it ...
Familiarize yourself with jQuery and its AJAX API. You can't make it not load a new page unless you use AJAX. Here is an example of what an AJAX call looks like:
$.ajax({
url: 'http://server.domain.com/cgi-bin/myfile.cgi',
data: {
x: 1,
today: '20110504',
user: 'Joe'
}
}).success(function(data, status, xhr) {
if (data)
alert(data);
});
That is for jQuery 1.5 or higher. You can run that whenever a certain button is clicked like this:
HTML for the button:
<input type="button" id="doThis"/>
JavaScript:
$(function() {
$('#doThis').click(function() {
//put AJAX sample shown above, here
});
});