How can i listen the Url changes event on a Phone browser control?
My requirement is page1.html will be loaded on browser by default. On click event of Submit button on page1.html , it will redirected internally to Page2.html with some parameters. So i want to capture those parameters . How can i do this? Is there any AddressChanged event or similar events can be added ?
try this:
private void Browser_Navigated(object sender,System.Windows.Navigation.NavigationEventArgs e)
{
string uri = e.Uri.OriginalString;
}
By using Browser_Navigated and Browser_Navigating both events u can get the Uri of current navigation along with all its parameters.
There is events Navigated and Navigating, where you can get current Uri in parameters and react accordingly.
Related
I want to reload search data again when popup is closed, I mean my app will go as an iframe in the main web app, so On button click, I don't want to reload my whole page as window.location.reload() , I want only my data should be reloaded,
Example- When I click yes in popup to remove something and when I close popup, It should reload the search data,
Suggest me for routing/any other method instead of window reload
Try to reload the function instead of reloading the window.
Seems like if u have function for loading the data like
foo(data:any){
--your code for loading data and binding
}
//popup close event
close(){
this.foo();
}
this will help u to reassign the data without reloading the window
I'm using JSF and Primefaces' dialog framework to open a dialog on a button click. I have an xhtml page that can be opened in both it's own page and within a dialog. Is there a way, within a managed bean call to check if the RequestContext is from a dialog?
Something like:
RequestContext.getCurrentInstance().isDialogContext();
and then conditionally invoke:
RequestContext.getCurrentInstance().closeDialog(null);
You have to check a specific request parameter.
It's a GET param, and it's appended by the script that launches the dialog on the contained iframe URL.
Check DialogNavigationHandler for details.
public static boolean isDialogContext()
{
return FacesContext.getCurrentInstance()
.getExternalContext()
.getRequestParameterMap()
.containsKey(Constants.DIALOG_FRAMEWORK.CONVERSATION_PARAM);
}
where Constants is org.primefaces.util.Constants
We are developing a web application with javascript, we use chrome as our default browser for our users.
Now we met a problem when we use window.open in our application.
In our application, we need to open new page in a new browser tab, we used code : window.open('http://ourUrl.com', '_blank') in js code;
The action of the browser is different according to when this line of code is executed.
situation 1: user clicked a button, the click event will trigger our js function, in this function, execute this line of code directly, then the browser may open the page in a new browser tab. (this is what we want.)
situation 2: user clicked a button, in the handler of the button's click event, we firstly submit the data on page to our server via ajax, and in the callback function, we execute this line of code, it may pop an independent new window without tool bar instead of a browser tab.(this is not what we want).
I don't understand why the action of browser is different, anyone can help to explain?
Thanks.
As I explained on this question, in order for a URL to be opened in a new tab (not new window), the window.open function must be called within a scope of a user generated action callback (for example, within the scope of onClick)
In any other scenario, the URL will be opened in a new window.
To explain what you're experiencing:
Situation 1: window.open is invoked in a callback for a user generated action. That's why it's opened in a new tab.
Situation 2: In this situation, the window.open function is invoked in the scope of an ajax response callback, which is a different scope (outside the context of) the user generated action.
For the second scenario to open a new tab (instead of window) you need to call window.open synchronously, immediately after the user's click, and not as a callback of another action (ajax response).
I am trying to write a JavaScript function that will open my extension like when the extension icon is clicked. I know how to open my extension in a new tab:
var url = "chrome-extension://kelodmiboakdjlbcdfoceeiafckgojel/login.html";
window.open(url);
But I want to open a pop-up in the upper right corner of the browser, like when the extension icon is clicked.
The Chromium dev team has explicitly said they will not enable this functionality. See Feature request: open extension popup bubble programmatically :
The philosophy for browser and page action popups is that they must be triggered by user action. Our suggestion is to use the new html notifications feature...
Desktop notifications can be used progammatically to present the user with a small HTML page much like your popup. It's not a perfect substitution, but it might provide the type of functionality you need.
Chrome team did create a method to open the popup programmatically, but it's only enabled as a private API, and plans to make it generally available have stalled due to security concerns.
So, as of March 2018 as of now, you still can't do it.
Short answer is that you cannot open browserAction programmatically. But you can create a dialog with your content script which emulates your browserAction and display that isntead (programmatically). However you won't be able to access your extension's background page from this popup directly as you can from your popup.html. You will have to pass message instead to your extension.
As mentioned there is no public API for this.
One workaround I have come up with is launching the extension as an iframe inside a content script with a button click. Whereby the background script emits the extension URL to the content script to be set as the iframe's src, something like below.
background.js
browser.runtime.onMessage.addListener((request) => {
if (request.open) {
return new Promise(resolve => {
chrome.browserAction.getPopup({}, (popup) => {
return resolve(popup)
})
})
}
})
content-scipt.js
const i = document.createElement('iframe')
const b = document.createElement('button')
const p = document.getElementById('some-id')
b.innerHTML = 'Open'
b.addEventListener('click', (evt) => {
evt.preventDefault()
chrome.runtime.sendMessage({ open: true }, (response) => {
i.src = response
p.appendChild(i)
})
})
p.appendChild(b)
This opens the extension in the DOM of the page the script is running on. You will also need to add the below to the manifest.
manifest.json
....
"web_accessible_resources": [
"popup.html"
]
....
You could emulate the popup by displaying a fixed html element on the page in the same location the popup would be and style it to look like the popup.
I had the same requirement: When the user clicks on the extension icon a small popup should open. In my case, I was writing an extension which will give updates on selective stocks whenever the icon is clicked. This is how my popup looked.
If you were having the same requirement then please read the answer below.
This is how my manifest.json file looked.
All the heavy lifting was handled by manifest.json file only. There is a section browser_action inside which there is a key called default_popup, just put the name of the HTML file that you want the popup to display.
I wanted my extension to work on all the pages that's why I added the attribute matches under content_scripts. I really didn't need to put the jquery file jquery-3.2.1.js inside the js array but the extension manager was not allowing me to keep that array empty.
Hope this helps, do comment if you have any doubt regarding the answer.
I would like my page action to be activated for all the outgoing links from a certain page. How might I go about doing that? I've gone over the docs to no avail. Any pointers would be appreciated!
Google Chrome API doesn't have such API, but functionality you want may be implemented using standard Google chrome Extensions API.
You need to implement content script
Your content script should modify DOM of the page you want to handle and override all outgoing links with your custom javascript which will do some stuff and open clicked link.
To modify link href you can do something like this:
function processLink(element, newHref) {
var a = document.createElement("a");
a.href = newHref;
a.textContent = element.textContent;
a.title = element.title;
element.parentNode.replaceChild(a, element);
}
UPDATE 1.
Instead of newHref you can generate something like
a.href = "javascript:processOutgoingLinkClick('" + element.href + "')"
Function processOutgoingLinkClick should contain actual processing of the click.
Just a curiosity, why wont you use the Chrome Extensions Tab Events you can listen for onUpdated onCreated. When a user clicks on a link on the page it will go and fire an event within onUpdated.
So within your background.html, you can do:
chrome.tabs.onUpdated.addListener(function(tabId, info) {
if (info.status === 'loading')
console.log('Loading url ... ' + info.url)
});
Same thing for onCreated. Then while its loading, you can decide what to do with your pageAction.