Change content dynamicly in google chrome extension development - javascript

I have login form in chrome extension. I check if username and password true. I want if user loggined in extension content (html page ) must be change. And after that when i clicked extension logo i dont want user see login page. How can i do that?

Your question is not very clear. But seems like you want to simply display different HTML page depending on whether a user has logged into your extension.
A simple way to do that is, make user first login to your extension. Define some variable like "logged-in-state", initialize it to "not-logged-in". Change it to name that the user logged in with after successful login. Flush this information to localStorage.
Next time when your extension starts, read this variable from the disk.
Every time, any page from your extension loads, make it send a message to background script requesting for that variable. If the value is "not-logged-in" then display login/password. Otherwise, display regular content.
Basically, assign various classes dynamically to HTML content for different states like logged-in/not-logged-in and have CSS rules that will hide based on the class value.

Related

Understanding anonymous user in Drupal 7 form using Jquery

I have site which contains many links. User can open links in new window. User can log out from one window. If they do so and click on the other window of my site then I want to give an alert to the user saying that "Please login to continue". My questions are:-
Is this possible in Drupal 7?
Is there any extra module to support this.
If there is no contributed module available for this then my idea is to register a click event on the page(document) inside JQuery which will always check if user is authenticated or not. I want to know that which function in Drupal will help me in understanding authenticated user of site in JQuery.
Please share if any other option available to achieve this goal.
This is not an easy task, but I am going to explain how I would do so (without too many details):
Create a web service which receives a cookie and returns whether it represents a live session or not.
Use the visibility change javascript event to detect when a user leaves the browser or comes back in. When you notice the user has come back to the browser, perform an AJAX call to the server you set up in step one. You should provide the cookie stored in the browser, and expect a boolean answer.
Depending on the response given by the server, display a modal dialog with Javascript showing a login form orwhatever you consider necessary.
Note: This method will only work if the user is using a browser supporting visibility change events, and can be bypassed disabling Javascript code execution. In addition, the user will still be able to see the content if the browser is not the focused window (for example, there are two opened windows, each of them covering one half of the screen. The event will not fire until the focus comes back to the "forbidden" window).

only open child webpage if it is no longer open or the url changed to a different site?

I do not want the webpage to reload if its already open, as this causes unnecessary data to be sent to the javascript application.
If the webpage is not open, I want it to be open.
If the webpage was open but the user used teh tab to load another webpage, i want a new webpage to open,.
If the webpage is open and still on the right url, I do not want any change, I do not want it to refresh.
However I can not seem to find a way to know if the url changed.
I can use cookies if i have to but would rather not. Any suggestions?
Thanks.

How can I make a tool-tip to automatically appear for my chrome extension which uses pageaction?

I want to have a message displayed automatically, whenever my pageaction icon is displayed.
How can I make that to be displayed, I want to alert the user that " You can click this button to perform so on....".
If you want a popup appear programmatically, this cannot be done, it can only be initiated by a user click.
It would be nice if you could use infobars API, but it is still experimental.
Therefore, your only choice seems to be to inject a script into the page that would create some sort of overlay on the page roughly pointing to the page action area.
Note that you will need permission to access that page, as activeTab permission is not enabled until user clicks on your page action.

How do pageActions and browserActions differ?

I'm a writing a chrome extension that allows users to do the following:
Load data into the popup when the icon is clicked
Change the data in the popup based on actions the user takes on the page
Append elements to the DOM of the page based on actions taken in the popup
It seems that I can accomplish 1 with a script in the browser_action field of the manifest, but perhaps I need a page_action script for 2 and 3?
The core of the problem is that I do not know exactly how browser_actions and page_actions differ from each other. My limited understanding is that page actions allow data populated in the popup to be manipulated dynamically. Is this true? I cannot find an explanation about the differences that makes sense to me.
Browser Action is a type of extensions that use icon on the right of address bar. You click on that icon and popup page is loading. Those extensions work regardless of page currently opened.
Page Action only works while certain webpage(s) is opened. It displays as an icon inside the address bar (near page URL). This is for extensions only working on certain websites.
If you want to make your extension working on every website, you should use browser_action.
For further information you may want to visit these pages:
http://developer.chrome.com/extensions/browserAction.html
http://developer.chrome.com/extensions/pageAction.html

How can I remove an iframe within an iframe on an external web page like Pinterest's bookmarklet?

I am in the process of making a bookmarklet that allows users to highlight text on an external web page.
It runs JavaScript code that appends a JavaScript file from my server to the current web page that takes the title of the current web page, the URL of the current web page, and then the highlight text of the current web page. Finally, the user would click a button to submit the data to my web server to be saved into the database.
I have two ways of doing this: (1) have a popup with the data in the URL as parameters, or (2) to have an iframe inserted into the current web page with a form to submit the data.
In the one with the popup (1), the users browser auto blocks the popup for every domain. How do I get around this? It seems like Facebook share and twitter tweet buttons bypass the popup blocker though...
In the one with the iframe (2), I want to remove the iframe from the DOM after submitting data. However, if I'm on another domain, I get an error saying I am denied access because of origin policy something. I know it's possible because Pinterest's bookmarklet does this, it inserts an iframe then removes it from the current DOM.
I am looking for information on how these solutions work, so I can do something similar with my bookmarklet.
I resolved this by adding a post message callback after saving the data from the iframe.

Categories

Resources