GET parameters on ajax call (into modal dialog) - javascript

On an html page i click on a link and i get a dialog which loads server content through an ajax call.
I cannot change the javascript that created this dialog neither the ajax callbacks .
I have the need to access the href of the clicked link from another javascript to change some content loaded into the dialog from the ajax call. This after the dialog shows up.
As i can only read the window.location of the current page (the page containing the dialog, not the page loaded into the dialog itself), is there a way to get the href of the clicked link that caused the dialog to show up ? (ie. the GET parameters of the ajax call)
Attaching a callback for every clicked link doesn't work reliably because i have to catch just the last one that caused the dialog to open...
-- edit --
Well i'm using jquery, but i don't think it's implementation dependant.
The question more generally is: if i cannot access the ajax callback, is there a way to obtain the url in the GET request that caused a div (some content) to update ? (assuming you can call a javascript function after the div is loaded, inside it).
ie. if it was a popup (window.open) i just have to read window.location to get the page called, but as it's a div loaded from an ajax request, how i can get the url called ?
thanks anyway~

Install Firefox (if you do not have it already)
Install Firebug extension
Enable firebug for your site
Click the Link that launches the dialog (reproduce the situation)
Open the firebug window (bottom right corner of firefox)
Under Net - >XHR tab you can see the exact URL call with all GET/POST parameters that was triggered.
Then explore firebug some more to see what other possibilities it offers!

Related

Triggering a click action of an <a href=url rel='noreferrer'> in the success of an ajax request

In my ember application, I have a dialog box with 'OK' and 'Cancel' buttons. On clicking on 'OK', an action will be triggered in which an ajax request will be sent and in its success, a new tab with a certain url has to be opened. I tried triggering a click in the success of the ajax request, but the pop up gets blocked. Here I want to use an
<a href=url rel='noreferrer'>
rel='noreferrer' because I want the new tab to occupy seperate browser memory and not that of the current window. Hence I cannot create an element with window.open() before the ajax request and then change the location(url) in the success of it. ( new tab opened using window.open() will occupy the memory of the window from which the new tab got triggered). It would really help if I could get a solution. Thanks in advance :)
While you are looking for a method to trigger a click action, it sounds like more broadly you are trying to create a noreferrer popup from inside of a javascript function. I think this would be possible using a two-part approach:
Open a new popup using window.open() containing only a small script tag. This will not trigger the popup blocker, though it would still be sharing the linking page's memory.
Use the script tag (inside the popup) to trigger an HTML meta redirect (which incorporates the no-referer option as described here.
Note that you cannot do this in a single step, as you can't do an HTML meta redirect into a new window, only the current window (source).

Chrome Extension: How to send data from Panel Window to Popup?

I am working on Chrome extension which on clicking extension Icon popsup a window(popup.html) which contain button for Video Play. Upon clicking of the button opens another button which is created by using window.create of type panel. Upon clicking of PLAY button on popup.html does following:
Make a DIV enabled
Create new window by calling window.create with name mypanel.html. It uses panel.js to make ajax call and DOM changes functions.
Make an Ajax call, get data and play Video
Now thing is, the data I am getting via AJAX call in panel.js. I want to send that data back to pop.html which itself is using file popup.js. How can I send data from panel window to back to Popup Window?
The standard method of communicating between parts of the extension is described in Messaging documentation.
However, you need to keep in mind that as soon as a popup is closed, it is unloaded and the JavaScript context is destroyed along with it. So it cannot receive messages when closed and will lose all state when reopened.
There are two solutions to this:
You could employ a background page to hold state (if set to be persistent) and route messages between parts of the extension, e.g. a popup can request the current state when opening. This is an old-school solution.
If all you need is to pass/persist some data, you can easily employ chrome.storage.local to do it. You can save data with panel.js and react to changes with chrome.storage.onChanged event. The extra bonus is that when a popup reopens, it can simply read the storage to build its initial state.

How can I get opened URL in browser-action panel

I am creating a browser-action button on the right side of toolbar so that I can show deals on my extension depending upon the opened URL in tab.
Upon going through SDK documentation I found this: https://developer.mozilla.org/en-US/Add-ons/SDK/Low-Level_APIs/ui_button_toggle#Attaching_panels_to_buttons but it says that it's supported only for Firefox 30 onwards which is an issue.
To achieve this thing, I used browser-action lib by Rob-W (source: https://github.com/Rob--W/browser-action-jplib)
Here is how it works:
Let's say, I have opened www.example.com, and it has 20 deals on my server. If I click on my browser-action button, it would open a panel showing deals depending upon the opened URL (with the help of an AJAX request)
Now the problem is:
The browser-action button (upon click) opens popup.html, and in my popup.html I have included popup.js. This is the file where I want access to the opened tab URL, so that I can perform the AJAX request. I do not get how can I pass the opened tab URL from main.js to popup.js.
sdk/tabs give you the access to current tab and from there you can get the location.
https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/tabs
I do not get how can I pass the opened tab URL from main.js to
popup.js.
Have you tried to use the port system.
to emit a message from a content script:
self.port.emit("myContentScriptMessage", myContentScriptMessagePayload);
To receive a message from the add-on code:
self.port.on("myAddonMessage", function(myAddonMessagePayload) {
// Handle the message
});
You can also use widget instead of the new UI module if you really want to target browsers before version 30, however it is depreciated and will probably be removed within the next few releases.

Work around for browser popup

I am trying to open a window based on a server call, but that window is blocked by browser as popup for certain users.
Here is the sample of code of what I am trying to do
<a onclick="validateuser()"></a>
In validate user, I am sending request to an external server.
The server sends response to another method openwindow()
In openwindow() I am calling window.open to open the particular page.
When I call openwindow() directly on onclick, the user is not blocked by popup.
This can't be fixed - the behaviour is by design. You need to tie your pop-up directly to some user action (like clicking a button) or find another way. You could open up a <div> with an <iframe> inside, perhaps.

Iframe/Popup redirecting opener window

I have a page located at x.com. On this page is a button that, when clicked, will launch a new window (using javascript's window.open() method) to a page that is located at z.com. The popup does a few things, then redirects the original window (the opener, x.com) to a different page based on some parameters defined in the popup.
This works fine in Firefox/Chrome, but not in IE. In IE (8 specifically, but I believe 7 also has this problem) the original window (the opener) is not redirected. Instead, a new window comes up and THAT window is redirected.
I've tried many different methods to try and get this to work, including changing the popup to an iframe loaded on the page and having a function on the opener that the popup/iframe call. The problem seems to be that IE refuses to allow cross-domain sites to talk to each other via javascript.
Is there a way around this? How can I get the parent window to redirect to a page based on parameters in a popup or iframe?
EDIT:
Here is some code for samples:
In a page on domainA.com, I have this:
<img src='/images/test.png' onclick="window.open('http://www.domainB.com/item.aspx', 'name', 'width=100,height=100,menubar=no,status=no,toolbar=no');" />
In item.aspx on domainB.com I have this in the javascript:
opener.location.href = 'http://www.somethingelse.com/';
In Firefox/Chrome, this works fine. In IE, when domainB.com tries to set location.href on opener (aka the parent window, which is domainA.com), it instead opens a new window, which is not what I want. I want it to redirect the opener (parent window) to the URL I specified.
Bara
Hi I solved my problem by doing the following
instead of using window.opener.location = "....
Use window.opener.document.location = "url". This worked for me.
Another thing is make sure that you are not redirecting from http into https this will also cause it to break.
Cheers
I ended up resolving it by doing the following:
I added an iFrame to my main page. The iFrame is in the same domain as my popup. The iFrame contains a button that, when clicked, will launch the popup.
The popup does it's thing, then changes the iFrame's hash tag to something like #change (so the url would be www.whatever.com/iframe.aspx#change). In the iFrame's javascript, I have a loop going that checks the hash to see if it says "change" and if so, it will redirect the parent page to wherever I want. This works beautifully.
Because I did not want the infinite loop on every single page, I do a browser check so that this only applies to IE. For all other browsers I just use window.opener which works fine.
Bara

Categories

Resources