I am new to angularjs , so this question might seems silly to experience ones , But i really not able to perform this , can any body tell me that how to come back to app from webview after reaching to specific url , Like i am opening a window in browser for payment process so what i need is that when url in webview comes up with a success msg , i want to close the webview and get back to my application , I goggled and found a way that in $window.open() we pass three parameters and through second i can do that , but don't know how to implement that , can any one provide me a way to deal that.
i studied thi link :- Tracking a child window across page loads
i tried this function too :-
if (!$window.closed){
if($window.location.href =="http://www.magentomobileshop.com/demo/index.php/payu/index/success")
{
$window.close()
}
}
Thanks
Please have a look on it :-
Close a child window in an Android app made with Angularjs
here is my updated Answer ...and I have tested it
and its working fine
var url = "test_Url";
var socialLoginWindow = window
.open(url,
'_blank',
'location=no');
// listen to page load
// events
socialLoginWindow
.addEventListener(
'loadstart',
function(
event) {
var url = event.url;
if (url == "http://www.magentomobileshop.com/demo/index.php/payu/index/success/") {
socialLoginWindow
.close();
}
});
And here is the reference link for it :-
https://forum.ionicframework.com/t/opening-external-link-and-closing-it-at-an-event/6660/9
Here "Loadstart" will track your every change of url in window.So, the current URL can be get from event.url
Cheers !!!
Happy coding.
Use $window.close() in $window service.
You can broadcast the result to another controller like this AngularJS – Communicating Between Controllers
can you check if this will answer your question
How to close browser window in AngularJS
You can use the $window.location.href to check for the particular URL to be true
Related
I am trying to automate a site in a WPF application with WebBrowser control.
The site checks for the javascript window.name in each page and throws an error if this does not match with the preset value.
Look at the sample below.
var id="1234";
if (window.name != id)
{
window.open("home.html", id)
}
Is there a way to get this value and set it when I create a new WebBrowser object?
I tried the following and my problem is resolved. Hope this may help somebody.
I first navigated the page to a blank page with this code.
var html = string.Format(
"<html><body><h4>Opening ...</h4><script type='text/javascript'>window.open('about:blank', '{0}');</script></body></html>",
popupWindowName);
var w = new Browser();
w.NavigateToString(html);
And then in the page is load completed event, I navigated to the original URL.
w.Navigate("https://somesite.com/page.aspx",
null, null, h);
The popup window name was changed to what I wanted and the session continuted correctly. This is not a solution to the problem I faced, but it is more like a work around.
I also had to deal with the popups that kept coming. I had handled the NewWindow2 event to handle the popups.
Let's say normally my users access our web page via https://www.mycompany.com/go/mybusinessname
Inside this web page, we have a iframe which actually comes from https://www.mycompany.com/myapp
Everything is working fine, except that if for some reason, the users come to know about this url https://www.mycompany.com/myapp. They can start accessing it directly by typing into the address bar.
This is what I want to prevent them from doing. Is there any best practice to achieve this?
==== Update to provide more background ====
The parent page which is https://www.mycompany.com is the company's page and it's maintained by some other team. So they have all the generic header and footer, etc. so each application is rendered as an iframe inside it. (This also means we cannot change the parent page's code)
If users access https://www.mycompany.com/myapp directly, they won't be able to see the header and footer. Yes, it's not a big deal, but I just want to maintain the consistency.
Another of my concern is that, in our dev environment (aka when running the page locally) we don't have the parent-iframe thing. We access our page directly from http://localhost:port. Hence I want to find a solution that can allow us access it normally when running locally as well.
If such solution simple does not exist, please let me know as well :)
On your iframe's source, you can check the parent's window by using window.top.location and see if it's set to 'https://www.mycompany.com/go/mybusinessname'. If not, redirect the page.
var myUrl = 'https://www.mycompany.com/go/mybusinessname';
if(window.top.location.href !== myUrl) {
window.top.location.href = myUrl;
}
I realized we already had a function to determine whether the page in running under https://www.mycompany.com. So now I only need to do the below to perform the redirecting when our page is not iframe
var expectedPathname = "/go/mybusinessname";
var getLocation = function (href) {
var l = document.createElement("a");
l.href = href;
return l;
};
if (window == window.top) { // if not iframe
var link = getLocation(window.top.location.href);
if (link.pathname !== expectedPathname) {
link.pathname = expectedPathname;
window.top.location.replace(link.href);
}
}
You can use HTTP referer header on server-side. If the page is opened in IFRAME - the referer contains parent page address. Otherwise, it is empty or contains different page.
I´ve implemented a proxy with a listener with the next exception :
listeners: {
exception: function () {
Ext.Msg.alert(BB.Text.getText('ERROR_TIMEOUT_TITLE'), BB.Text.getText('ERROR_TIMEOUT_MSG') + '' + PROXY_TIMEOUT, Ext.emptyFn);
Ext.redirectTo('http://www.google.es'); //for example
}
}
After the message I would like to redirect to other page / view but It is not working correctly
What am I doing wrong??
Thanks.
For Sencha Touch
You probably want to read the documentation:
Documentation
http://docs.sencha.com/touch/2.4/apidocs/#!/api/Ext.app.Application-method-redirectTo
Quote
Redirects the browser to the given url. This only affects the url after the '#'.
Read the second part very carefully.
By the way this is the same as:
MyApp.app.redirectTo('http://www.google.es')
It take it from your post that you want to redirect to a different page inside a webapp.
Can be found here
WebApp: window.location.href = "http://www.google.es"
I think below line would solve your purpose.
Ext.app.Application.redirectTo('http://www.google.es');
Currently I am using message passing to send a request from my contentscript for data in localStorage and I am not having any issues with that, the content script is working as expected.
Can you do this in the other direction?
I have an object that exists in the content script that has a method called ".apply()" and I want to run it when the used clicks the option to do so.
I tried to make a listener in the content script like this:
var myLinker = new Linker();
chrome.extension.onRequest.addListener(function(request) {
if (request.method == "apply")
{
myLinker.apply("nothing");
alert("applied");
}
else
; //Do nothing
And send requests to it like this:
chrome.extension.sendRequest({method: "apply"}, function(){
alert("Tried to request");
});
I get that it is a bit of a hack, but it is the only thing I could think of, and it doesn't even work =/
Is there a way to do this?
I am pretty sure I could just inject new code into the page from the popup (I think I saw an api function for that), and then run stuff, but that would take more memory and just feels like a bad way to do it, because you would basically have the exact same code twice.
To send a message from the extension to a content script, use chrome.tabs.sendMessage instead of chrome.extension.sendRequest.
Because sendRequest has been superseded by onMessage in Chrome 20, there's no official documentation for sendRequest any more. The documentation for chrome.tabs.sendMessage can be found here. Please note that these events cannot be mixed, use either *Request or *Message.
Yes, you would use this: http://developer.chrome.com/extensions/tabs.html#method-sendMessage
Content scripts live within the DOM of the page. And each page that is open within Chrome has a tab ID associated with it -- http://developer.chrome.com/extensions/tabs.html#type-tabs.Tab
Let's say you want to send the {method: "apply"} to a page that was just opened in a new tab:
chrome.tabs.onCreated.addListener(function(tab) {
chrome.tabs.sendMessage(tab.id, { method: "apply" });
});
There are other events/methods to get the specific Tab you want to send the message to. I think there's one called getCurrent to send to the currently selected tab, check out the docs for that.
I followed the example code from the addon dev site have successfully put a button onto FF :)
now i want to make that button do something interesting so I thought I would run an alert with the address that is currently in the bar... but this does not work:
CustomButton = {
1: function () {
alert("Just testing 1"+document.location.href);
},
}
except for the +document.location.href it's the exact demo code I got from the dev site...
You should note that in extension developing, document and window variables refers to the Host Browser not the browser that contains the web site.
you should use
gBrowser.selectedTab
for getting current tab and then using
currentURI.host
for getting URL host
also note that selectedTab returns a tab variable then you should get the window of that tab.
then the whole code will be:
gBrowser.getBrowserForTab(gBrowser.selectedTab).currentURI.host
Do you want to get the location of current document or the string that is in the location bar?
For location of current document
content.location.href
For the string in location bar
document.getElementById("urlbar").value
or
gURLBar.value
Those work for me, what context are you using it/how are you calling the function?
> document.location.href
< "http://stackoverflow.com/questions/6352035/firefox-addon-javascript-get-url-from-bar"
You can also use window.location.href
> window.location.href
< "http://stackoverflow.com/questions/6352035/firefox-addon-javascript-get-url-from-bar"
Try alert("The current page URL is " + browser.currentURI.spec) and see how that goes for you.
See also:
Firefox extension development : Get URL of new tab and https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIURI
Took a while to figure it all out:
gBrowser.currentURI.spec;
is how you do it.
Here's some code you may find useful
window.addEventListener('load', function (e) {
var href = gBrowser.currentURI.spec;
if ( href.match(/website.com/) ) {
var contentDoc = content.document;
// Do some stuff to the current website.com's DOM
}
}, true);