{"id":17815,"date":"2024-03-15T15:45:13","date_gmt":"2024-03-15T15:45:13","guid":{"rendered":"https:\/\/www.silicloud.com\/blog\/how-to-get-values-from-the-parent-page-in-layui-pop-up-layer\/"},"modified":"2024-03-21T11:48:42","modified_gmt":"2024-03-21T11:48:42","slug":"how-to-get-values-from-the-parent-page-in-layui-pop-up-layer","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/blog\/how-to-get-values-from-the-parent-page-in-layui-pop-up-layer\/","title":{"rendered":"How to get values from the parent page in layui pop-up layer?"},"content":{"rendered":"<p>There are several ways to retrieve the value of the parent page in a pop-up layer.<\/p>\n<ol>\n<li>Using localStorage:<br \/>\nStore the value that needs to be passed in the parent page&#8217;s localStorage, and then in the pop-up layer, use window.parent.localStorage.getItem() method to retrieve the value from the parent page.<\/li>\n<\/ol>\n<p>Parent page:<\/p>\n<pre class=\"post-pre\"><code><span class=\"hljs-variable language_\">localStorage<\/span>.<span class=\"hljs-title function_\">setItem<\/span>(<span class=\"hljs-string\">'data'<\/span>, <span class=\"hljs-string\">'\u7236\u9875\u9762\u7684\u503c'<\/span>);\r\n<\/code><\/pre>\n<p>Popup:<\/p>\n<pre class=\"post-pre\"><code><span class=\"hljs-keyword\">var<\/span> data = <span class=\"hljs-variable language_\">window<\/span>.<span class=\"hljs-property\">parent<\/span>.<span class=\"hljs-property\">localStorage<\/span>.<span class=\"hljs-title function_\">getItem<\/span>(<span class=\"hljs-string\">'data'<\/span>);\r\n<span class=\"hljs-variable language_\">console<\/span>.<span class=\"hljs-title function_\">log<\/span>(data); <span class=\"hljs-comment\">\/\/ \u8f93\u51fa\uff1a\u7236\u9875\u9762\u7684\u503c<\/span>\r\n<\/code><\/pre>\n<ol>\n<li>Passing parameters using URL:<br \/>\nWhen opening a pop-up window, pass the required values as URL parameters to the URL of the pop-up window, and then use window.location.search in the pop-up window to retrieve the URL parameters.<\/li>\n<\/ol>\n<p>Parent page<\/p>\n<pre class=\"post-pre\"><code><span class=\"hljs-keyword\">var<\/span> data = <span class=\"hljs-string\">'\u7236\u9875\u9762\u7684\u503c'<\/span>;\r\n<span class=\"hljs-variable language_\">window<\/span>.<span class=\"hljs-title function_\">open<\/span>(<span class=\"hljs-string\">'popup.html?data='<\/span> + <span class=\"hljs-built_in\">encodeURIComponent<\/span>(data));\r\n<\/code><\/pre>\n<p>Popup layer (popup.html):<\/p>\n<pre class=\"post-pre\"><code><span class=\"hljs-keyword\">var<\/span> urlParams = <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-title class_\">URLSearchParams<\/span>(<span class=\"hljs-variable language_\">window<\/span>.<span class=\"hljs-property\">location<\/span>.<span class=\"hljs-property\">search<\/span>);\r\n<span class=\"hljs-keyword\">var<\/span> data = urlParams.<span class=\"hljs-title function_\">get<\/span>(<span class=\"hljs-string\">'data'<\/span>);\r\n<span class=\"hljs-variable language_\">console<\/span>.<span class=\"hljs-title function_\">log<\/span>(<span class=\"hljs-built_in\">decodeURIComponent<\/span>(data)); <span class=\"hljs-comment\">\/\/ \u8f93\u51fa\uff1a\u7236\u9875\u9762\u7684\u503c<\/span>\r\n<\/code><\/pre>\n<ol>\n<li>To access the parent window from a pop-up window, use window.opener to retrieve the parent&#8217;s window object, and then use methods like window.opener.document.getElementById() to access the parent&#8217;s element values.<\/li>\n<\/ol>\n<p>Parent page:<\/p>\n<pre class=\"post-pre\"><code><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">input<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">\"text\"<\/span> <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\">\"data\"<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"\u7236\u9875\u9762\u7684\u503c\"<\/span>&gt;<\/span>\r\n<\/code><\/pre>\n<p>Pop-up layer:<\/p>\n<pre class=\"post-pre\"><code><span class=\"hljs-keyword\">var<\/span> data = <span class=\"hljs-variable language_\">window<\/span>.<span class=\"hljs-property\">opener<\/span>.<span class=\"hljs-property\">document<\/span>.<span class=\"hljs-title function_\">getElementById<\/span>(<span class=\"hljs-string\">'data'<\/span>).<span class=\"hljs-property\">value<\/span>;\r\n<span class=\"hljs-variable language_\">console<\/span>.<span class=\"hljs-title function_\">log<\/span>(data); <span class=\"hljs-comment\">\/\/ \u8f93\u51fa\uff1a\u7236\u9875\u9762\u7684\u503c<\/span>\r\n<\/code><\/pre>\n<p>Here are some common methods for obtaining values from the parent page. Choose the one that best suits your needs based on your specific situation.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are several ways to retrieve the value of the parent page in a pop-up layer. Using localStorage: Store the value that needs to be passed in the parent page&#8217;s localStorage, and then in the pop-up layer, use window.parent.localStorage.getItem() method to retrieve the value from the parent page. Parent page: localStorage.setItem(&#8216;data&#8217;, &#8216;\u7236\u9875\u9762\u7684\u503c&#8217;); Popup: var data [&hellip;]<\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-17815","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to get values from the parent page in layui pop-up layer? - Blog - Silicon Cloud<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/blog\/how-to-get-values-from-the-parent-page-in-layui-pop-up-layer\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to get values from the parent page in layui pop-up layer?\" \/>\n<meta property=\"og:description\" content=\"There are several ways to retrieve the value of the parent page in a pop-up layer. Using localStorage: Store the value that needs to be passed in the parent page&#8217;s localStorage, and then in the pop-up layer, use window.parent.localStorage.getItem() method to retrieve the value from the parent page. Parent page: localStorage.setItem(&#039;data&#039;, &#039;\u7236\u9875\u9762\u7684\u503c&#039;); Popup: var data [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/blog\/how-to-get-values-from-the-parent-page-in-layui-pop-up-layer\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-03-15T15:45:13+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-21T11:48:42+00:00\" \/>\n<meta name=\"author\" content=\"Isabella Edwards\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:site\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Isabella Edwards\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-get-values-from-the-parent-page-in-layui-pop-up-layer\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-get-values-from-the-parent-page-in-layui-pop-up-layer\/\"},\"author\":{\"name\":\"Isabella Edwards\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/5579144e23c225c8188167f3e3f888dd\"},\"headline\":\"How to get values from the parent page in layui pop-up layer?\",\"datePublished\":\"2024-03-15T15:45:13+00:00\",\"dateModified\":\"2024-03-21T11:48:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-get-values-from-the-parent-page-in-layui-pop-up-layer\/\"},\"wordCount\":175,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-get-values-from-the-parent-page-in-layui-pop-up-layer\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/how-to-get-values-from-the-parent-page-in-layui-pop-up-layer\/\",\"name\":\"How to get values from the parent page in layui pop-up layer? - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\"},\"datePublished\":\"2024-03-15T15:45:13+00:00\",\"dateModified\":\"2024-03-21T11:48:42+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-get-values-from-the-parent-page-in-layui-pop-up-layer\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/blog\/how-to-get-values-from-the-parent-page-in-layui-pop-up-layer\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-get-values-from-the-parent-page-in-layui-pop-up-layer\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.silicloud.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to get values from the parent page in layui pop-up layer?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"name\":\"Silicon Cloud Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\",\"name\":\"Silicon Cloud Blog\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"contentUrl\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"width\":1024,\"height\":1024,\"caption\":\"Silicon Cloud Blog\"},\"image\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\",\"https:\/\/twitter.com\/SiliCloudGlobal\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/5579144e23c225c8188167f3e3f888dd\",\"name\":\"Isabella Edwards\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d4d4dec47f553ac7961d9fa4cc9bdcdcf5b7ce5106594330b6d25c5694fdbaec?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d4d4dec47f553ac7961d9fa4cc9bdcdcf5b7ce5106594330b6d25c5694fdbaec?s=96&d=mm&r=g\",\"caption\":\"Isabella Edwards\"},\"url\":\"https:\/\/www.silicloud.com\/blog\/author\/isabellaedwards\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to get values from the parent page in layui pop-up layer? - Blog - Silicon Cloud","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/blog\/how-to-get-values-from-the-parent-page-in-layui-pop-up-layer\/","og_locale":"en_US","og_type":"article","og_title":"How to get values from the parent page in layui pop-up layer?","og_description":"There are several ways to retrieve the value of the parent page in a pop-up layer. Using localStorage: Store the value that needs to be passed in the parent page&#8217;s localStorage, and then in the pop-up layer, use window.parent.localStorage.getItem() method to retrieve the value from the parent page. Parent page: localStorage.setItem('data', '\u7236\u9875\u9762\u7684\u503c'); Popup: var data [&hellip;]","og_url":"https:\/\/www.silicloud.com\/blog\/how-to-get-values-from-the-parent-page-in-layui-pop-up-layer\/","og_site_name":"Blog - Silicon Cloud","article_publisher":"https:\/\/www.facebook.com\/SiliCloudGlobal\/","article_published_time":"2024-03-15T15:45:13+00:00","article_modified_time":"2024-03-21T11:48:42+00:00","author":"Isabella Edwards","twitter_card":"summary_large_image","twitter_creator":"@SiliCloudGlobal","twitter_site":"@SiliCloudGlobal","twitter_misc":{"Written by":"Isabella Edwards","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.silicloud.com\/blog\/how-to-get-values-from-the-parent-page-in-layui-pop-up-layer\/#article","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/how-to-get-values-from-the-parent-page-in-layui-pop-up-layer\/"},"author":{"name":"Isabella Edwards","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/5579144e23c225c8188167f3e3f888dd"},"headline":"How to get values from the parent page in layui pop-up layer?","datePublished":"2024-03-15T15:45:13+00:00","dateModified":"2024-03-21T11:48:42+00:00","mainEntityOfPage":{"@id":"https:\/\/www.silicloud.com\/blog\/how-to-get-values-from-the-parent-page-in-layui-pop-up-layer\/"},"wordCount":175,"commentCount":0,"publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/blog\/how-to-get-values-from-the-parent-page-in-layui-pop-up-layer\/","url":"https:\/\/www.silicloud.com\/blog\/how-to-get-values-from-the-parent-page-in-layui-pop-up-layer\/","name":"How to get values from the parent page in layui pop-up layer? - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/#website"},"datePublished":"2024-03-15T15:45:13+00:00","dateModified":"2024-03-21T11:48:42+00:00","breadcrumb":{"@id":"https:\/\/www.silicloud.com\/blog\/how-to-get-values-from-the-parent-page-in-layui-pop-up-layer\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/blog\/how-to-get-values-from-the-parent-page-in-layui-pop-up-layer\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/blog\/how-to-get-values-from-the-parent-page-in-layui-pop-up-layer\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.silicloud.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to get values from the parent page in layui pop-up layer?"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/blog\/#website","url":"https:\/\/www.silicloud.com\/blog\/","name":"Silicon Cloud Blog","description":"","publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.silicloud.com\/blog\/#organization","name":"Silicon Cloud Blog","url":"https:\/\/www.silicloud.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","contentUrl":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","width":1024,"height":1024,"caption":"Silicon Cloud Blog"},"image":{"@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/SiliCloudGlobal\/","https:\/\/twitter.com\/SiliCloudGlobal"]},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/5579144e23c225c8188167f3e3f888dd","name":"Isabella Edwards","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d4d4dec47f553ac7961d9fa4cc9bdcdcf5b7ce5106594330b6d25c5694fdbaec?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d4d4dec47f553ac7961d9fa4cc9bdcdcf5b7ce5106594330b6d25c5694fdbaec?s=96&d=mm&r=g","caption":"Isabella Edwards"},"url":"https:\/\/www.silicloud.com\/blog\/author\/isabellaedwards\/"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/17815","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/comments?post=17815"}],"version-history":[{"count":1,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/17815\/revisions"}],"predecessor-version":[{"id":51452,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/17815\/revisions\/51452"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/media?parent=17815"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/categories?post=17815"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/tags?post=17815"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}