This is also a problem encountered in the project:
There are a.html and b.html.
1.a page has been opened, B page has not been opened, I would like to set some column in a page parameters, such as background color, width and other parameters, passed to the B page, so that b page can be applied on the open.
The 2.a page is already open and the B page is open or not. On page a you need to get some elements and even variables for page B so that you can apply to page a.
Note: Cross-domain issues are not involved.
Thought for a long time, finally thought of the solution.
The first problem is that we can use the attributes of the HTML page anchor to pass the parameters to the B page via URL
This is the A page code:
<button> Jump Settings </button>
<script>
var btn = document.queryselector (' button ');
Console.log (window);
Btn.addeventlistener (' click ', Function () {
window.location = ' ci.html#bgc= #369? wd=500 '
})
</ Script>
By the code can know, click the button jump page, jump URL after a series of parameters, this will not affect the address of the jump, when the B page opened, you can get location intercept string to obtain variables and variable values, and then apply.
This is the B page code:
<div></div>
<script>
var div = document.queryselector (' div ');
var bl = window.location.hash.slice (1). Split ('? ');
if (bl.length >= 1) {for
(var i = 0; i < bl.length i + 1) {
switch (bl[i].split (' = ') [0]) {case
' BGC ':
document.body.style.background = bl[i].split (' = ') [1];
break;
Case ' WD ':
div.style.width = bl[i].split (' = ') [1] + ' px ';
break;
Default:
null;
break;
}
}} </script>
Gets the variable application that the URL passes over by intercepting the string. Success!
The second question, I think, is to achieve the goal through the IFRAME, which is just a decoy.
Create an IFRAME dynamically on page A and set the SRC value to page B, display none. The Contentdocument property of the IFRAME is then used to obtain the returned IFrame's document.
Get the required elements within the document and apply them.
Source:
<span>11111111111</span>
<script>
var fram = document.createelement (' iframe ');
FRAM.SRC = ' http://www.vip.com/kongzhi/fram2.html ';
Fram.style.display = ' None ';
Document.body.appendChild (FRAM);
Fram.onload = function () {
var doc = fram.contentdocument | | fram.contentWindow.document;
var p = doc.queryselector (' P ');
Document.body.appendChild (P);
}
</script>
The above is a small set to introduce JS control static page transfer parameters and get parameter application, I hope to help everyone, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!