Page jump executes the JS code $ (function () {}); URL parameter passing
The first part of the title does not have to be mentioned, the button can also be replaced with hyperlinks.
Assume that you need a button on the a page, click to jump to the B page, pass some parameters and the B page of a JS function can execute ~ ~
The key is how to jump to the target page and "then" execute the "JS function of the target page". The reason is that a certain JS function of the target page is the one that needs to click the page button or hyperlink to trigger, but now need to jump to B page immediately after the execution!
I don't want to jump from page A to page B, assuming you want to do it on page B, you need to write the code logic in the $ (function () {}); This is the idea of a breakthrough.
We define a button on page A to trigger the action shown in title:
HTML code
- <button type="button" class="btn btn-info" onclick="OpenReport ()"> Open Report </button>
It corresponds to the JS function:
JS Code
- function OpenReport () {
- window.open ("B-page url?flag=true&a=" +a,' NewWindow ',' height=1100,width=1400 ');
- }
At the same time, 2 parameters were passed to page B of target page: flag and A.
The $ (fucntion () {}) of the JS file on page b; Add this section of code (key), such as:
JS Code
- var url = window.location.href; //Get the URL of the current browser
- index = url.indexof ("flag"); To determine if the current URL has flag, if any, the description is to jump from a page, execute the following program
- if (index!=-1) {//jump from page A to
- //Parameter Preparation
- var start = Url.indexof ("A");
- var a = url.substring (start + "a". length+1);
- var date = new Date ();
- var year = Date.getfullyear (); //When the year before
- var month = Date.getmonth () + 1; //Current month (month is starting from 0, so must be added 1)
- month = month<10? ("0" +month): Month;
- var querydate = year + month;
- //+ "&suffix=" + encodeURI (encodeURI (suffix));
- var url= "Ajax URL?" A= "+ A +" &querydate= "+ querydate;
- //With parameter execution logic
- $.ajax ({
- Url:url, DataType:"html", headers:{"x-fragment":"_"},
- Cache:false,
- Success: function (HTML) {
- //Logical processing after a successful response
- }
- });
- }
This code is very typical, for the a page passed over the parameters of the receive in the code's comments are explained in great detail.
By the way, also review the JS get system year and month usage.
The magical magic of the flag variable here is a clever ~ ~ ~
From: http://raising.iteye.com/blog/2283257 Iteye in the best effort
Click the button (or hyperlink) to jump to another page and execute the JS function of the target page