How could i pass some data to my window.open() ?
For example:
I am in site1.com and using
window.open("http://site2.com");
The questing is - how to crossbrowser pass some data via js to that site1.com
The easiest way to pass data between pages is to build a query string like this:
window.open("http://site2.com?parameter1=foo¶meter2=bar&etc=whatever");
When one page opens another the function window.opener() can return values to a particular function in the opening page. Look it up for details. I don't have a development box in front of me so its difficult to show good examples. I know I've done it this way in the past. Like a popup allowing choices to be made by user then close child form and pass choice back to parent form.
Related
For a f:link show action in my fluid list template i want to pass a javascript variable to the arguments, basically the uid (to pass that specific object to the showAction), but it doesn't work the way i intend to do it. Is there a workaround for this particular problem?
The naked template looks like this:
<f:for each="{termins}" as="termin">
<tr>
<td><f:link.action action="show" arguments="{termin : termin}"> {termin.mitarbeiter}</f:link.action></td>
<td><f:link.action action="show" arguments="{termin : termin}"> {termin.kunde}</f:link.action></td>
</tr>
</f:for>
</table>
You can't - and you also can't (read: never should) generate links to controller actions from JS since it needs to generate a security checksum. Modifying the URL you create will generate a security error. The checksum exists to prevent DDOS so it has good reason.
There are two options:
You can generate all links in advance
You can make a link-generating service that you call with XHR to generate the necessary links from JS.
Only the first one is appropriate to your use case. Especially so since you want to pass UID values which always refer to an object in the database - which means you can easily generate a list of links to all possible detail views, then read/pass that list of links from your JS to select the right one.
The JS is something working after the fluid template. The right order is, your fluid template is parsed into the HTML, and then the browser render the HTML/JS/CSS to you. So, you can not expect to use JS value in your fluid template.
There are 2 possibilities:
1) Instead of a link use a form and transmit it via POST. Set a form field dynamically with JavaScript. That way your variable isn't included in the (cHash-) checksum.
2) Create an AJAX action that accepts your variable as argument. Let it generate a valid link. Use POST to call it with your variable data. Show the link on your page with JavaScript.
I'm currently working on a PHP 5.3 based CMS. A lot of actions are called using GET Parameters.
Example:
index.php?action=create_module
adds a certain module to the database and displays the module structure again. There are also functions (triggered by simple links, no POST request) for removing and ordering modules, working the same way with GET parameters.
Problem with this: If the users clicks on History Back after two actions on that page, the whole action is triggered again, which I would like to avoid.
How can I solve this issue? Searched the internet already, but with no satisfying results.
Is there a jQuery function which can remove this ?action parameter when using the browser Back button?
If not, can I prevent the browser from going back?
Is there a way to trigger this "Page has expired" notice?
Different approach on the PHP side?
Note: Header("Location:..") is no option, and I would like to avoid AJAX here.
Thank you for your help!
You could add an event listener on 'onpopstate' to clean window.location.search which holds the parameters, see http://html5doctor.com/history-api/ to get more info about HistoryAPI.
I am developing my first website. At this time i am generating a new html design that would be a ticket.
From my main page, i will load this html when the user clicks the "See ticket" button. This html has a table which is filled on document.ready with javascript. The data used is a JSON created in the main page.
I coded a working solution using localStorage. The problem is that the next step is to convert that HTML website to PDF and the software i am using does not work properly with localStorage, so i need to pass the JSON from main page to the ticket page. I can't neither use URL encoding cause string could be sometimes longer than 2000 characters and it is not productive.
So i thought that maybe i could do and $.get call from the ticket.html to index.html and get the needed JSON. Is this approach correct, or is there any better solution?
Regards
As suggested earlier comments, you need to use serverside code to accept post params and you need to do a ajax post to send the data. This is very good approach. I have one more idea for implementing this.
Let say you open ticket.html in a window.open. And have a JS function ( say GetValue) in index.html, that returns JSON . So you need to get JSON in ticket.html.
You need to define a JS function in ticket.html , using windown.opener.GetValue() , you can get JSON value.
Hope, i am in same direction, which you need. If not, please clarify.
Other way, would be use iFrame and use message communication to pass large data between them, you are interested in this, please read this - https://developer.mozilla.org/en-US/docs/Web/API/Window.postMessage
I have a simple news update interface where I read news headlines/titles from a database and print them on page as a list. The goal is, that when I click one of the headlines it brings out an area with a form where the news article could be modified and then updated back into database.
Now in order to do that I need to somehow pass the information (an id, or the headline itself) on to the form, so I can there read the proper article and other info from the database. It seems like a very simple task, but I've come to notice it seems like an impossible task. I could of course put the whole form inside a javascript function and then pass on the headline as a parameter using this.innerHTML to the function and then read it from a variable, but then I'd have to generate all the html using javascript, or php, but I think there must be a simpler way to do this.
I've tried using a hidden input tag and others like span and div elements and then pass the headline there as the input elements value using onclick="document.getElementByID("elementsname").value=this.innerHTML;" and onclick="document.getElementsByName("elementname")[0].setAttribute("value/name", this.innerHTML);". Something like this would be so simple, but for some reason unknown to me these methods don't work. Either the info doesn't get there, or it's not further readable from the elements by javascript.
For example I can pass on the info using input element when setting it to type="text" and it shows up on the page as a text field, but it's not readable from there for some reason and it doesn't even appear on the code when checking the source code from the browser. Why is this? For that reason I can't get the info passed to my SQL query, so I could read the corresponding news article in to a textarea from database.
So, is there a way to somehow make that idea to work, or should I forget it and use other methods? How is this usually done anyway by web developers when they want to open something for editing/updating from database?
This approach is usually going to be accomplished using ajax and a separate template view for the form which is populated dynamically server side.
You will have your page of news articles. When one is clicked, it will make an ajax request to your server with an identifier for the article. The server will compose a page containing a WYSIWYG editor pre-filled with the information from the article inside of a set of input elements along with a save or cancel action.
The response from the server with this template page will come in the success callback in your page of news articles which will then popup a modal type of element containing the server side produced view.
Upon completing changes if the view is saved an update is called to the relevant news article on the page, as well as posting the changes to the server.
I have the need to pass the current model of the view, from the view into a controller, upon a button click.
This is to export the current data to Excel.
What is the best way to do this? I keep trying to pass the Model from the view into a JS function as such:
onclick = "ExportToExcel(this.Model);"
But, the data is being passed into the JS as undefined. What am I doing wrong?
Thanks.
The Model, after reaching the View from Controller (initially at the page load) is no longer accessible, I mean it sort of does not exist any more as an Object you can say. So, you cannot directly pass the model back to JS/Controller. If you want to pass any particular data from Model to JS, you can do so by actually "writing" the data in a hidden input and access this from Java Script using the input id by jQuery.
PS: I know this is pretty old question but I just wanted to know if I'm correct about this. :)
You can use jQuery to post your model object using and as #Raynos said, get download link.
To do that, you'll to convert your model (cs/vb) to javascript.
the onclick code will get run in global scope so this === window.
I'd assume window.Model is undefined
Try
element.onclick = function() {
ExportToExcel(this.Model);
};
For the record, exporting data to excel should be done on the server and should return a link to an excel file that get's temporary created on the server that users can download