How to use navigateFrame method in Puppeteer

Best JavaScript code snippet using puppeteer

Run Puppeteer automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

frame.js

Source: frame.js Github

copy
1/**
2 Title:框架控制所需要的JS代码
3 author:侯博
4 date:2005年07-07日
5 */
6
7//var rootpath = "/TopIcms";
8var webroot = document.location.href;
9webroot = webroot.substring(webroot.indexOf('//') + 2, webroot.length);
10webroot = webroot.substring(webroot.indexOf('/') + 1, webroot.length);
11webroot = webroot.substring(0, webroot.indexOf('/'));
12var rootpath = '/' + webroot;
13
14/*以下几个方法是利Dreamweaver自动产生的代码,主要用于控制图片的变换效果*/
15function MM_preloadImages() { //v3.0
16    var d = document;
17    if (d.images) {
18        if (!d.MM_p) d.MM_p = new Array();
19        var i,j = d.MM_p.length,a = MM_preloadImages.arguments;
20        for (i = 0; i < a.length; i++)
21            if (a[i].indexOf("#") != 0) {
22                d.MM_p[j] = new Image;
23                d.MM_p[j++].src = a[i];
24            }
25    }
26}
27
28function MM_swapImgRestore() { //v3.0
29    var i,x,a = document.MM_sr;
30    for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
31}
32
33function MM_findObj(n, d) { //v4.01
34    var p,i,x;
35    if (!d) d = document;
36    if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
37        d = parent.frames[n.substring(p + 1)].document;
38        n = n.substring(0, p);
39    }
40    if (!(x = d[n]) && d.all) x = d.all[n];
41    for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
42    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
43    if (!x && d.getElementById) x = d.getElementById(n);
44    return x;
45}
46
47function MM_swapImage() { //v3.0
48    var i,j = 0,x,a = MM_swapImage.arguments;
49    document.MM_sr = new Array;
50    for (i = 0; i < (a.length - 2); i += 3)
51        if ((x = MM_findObj(a[i])) != null) {
52            document.MM_sr[j++] = x;
53            if (!x.oSrc) x.oSrc = x.src;
54            x.src = a[i + 2];
55        }
56}
57
58//隐藏整个视图区
59function hideViewArea() {
60	top.document.getElementById("main").cols = "6,*";
61	parent.document.getElementById("viewArea").cols = "0,6";
62    var imageId = top.viewFrame.sizeControlFrame.document.getElementById("image");
63    var imgSrc = "<a href=" + "javascript:showViewArea();" + "><img src='../" + "img/frame/showRight.gif' name='leftImage' width='7' height='50' border='0' id='leftImage' onMouseOver=" + " MM_swapImage('leftImage','','../" + "img/frame/showRightOver.gif',1)" + " onMouseOut=" + " MM_swapImgRestore()" + "></a>";
64    imageId.innerHTML = imgSrc;
65}
66
67//显示整个视图区
68function showViewArea() {
69    top.main.cols = "180,*";
70    top.viewFrame.viewArea.cols = "170,6";
71    var imageId = top.viewFrame.sizeControlFrame.document.getElementById("image");
72    var imgSrc = "<a href=" + "javascript:hideViewArea();" + "><img src='../" + "img/frame/hideLeft.gif' name='leftImage' width='7' height='50' border='0' id='leftImage' onMouseOver=" + " MM_swapImage('leftImage','','../" + "img/frame/hideLeftOver.gif',1)" + " onMouseOut=" + " MM_swapImgRestore()" + "></a>";
73    imageId.innerHTML = imgSrc;
74}
75
76
77//菜单转向时把页面标题提到headFrame中去,然后在改变主页面的href地址
78function toURL(name, url) {
79    //把页面标题提交到Head页面中
80    //top.headFrame.pageTitle.value = name;
81    pageTitle.value = name;
82    //清空导航栏,并隐藏
83    //clearNavList();
84    //跳转页面
85    top.mainFrame.location.href = url;
86}
87
88//布局框架页面中提取headFrame中题的值
89function getPageTitle() {
90    var pageTitleStr = top.headFrame.pageTitle.value;
91    var pageTitleId = document.getElementById("pageTitle");
92    pageTitleId.innerHTML = pageTitleStr;
93}
94
95//导航栏上的资料入口
96function navToURL(url) {
97    //    top.headFrame.isShowNav.value = 'true';
98    top.mainFrame.location.href = url;
99}
100
101
102/** -----------------导航栏使用的函数--------------------- **/
103//checks browser and sets up layers accordingly
104//var path = "default/images/navigate/";
105var path = rootpath + "/frame/" + "default/images/navigate/";
106//imgArray 是一个二维数组:[imgName,on_img_src,off_img_src]
107var imgArray = [
108        ["img1",path + "tab1_on.gif", path + "tab1_off.gif"] ,
109        ["img2",path + "tab2_on.gif", path + "tab2_off.gif"] ]
110
111//显示导航栏中的第一个面板,并隐藏其他面板
112function showOne() {
113    initnavigate();
114    updateTabs('img1');
115    showLayer('one');
116    hideLayer('two');
117    showNavigateView();
118}
119
120//显示导航栏中的第二个面板,并隐藏其他面板
121function showTwo() {
122    initnavigate();
123    updateTabs('img2');
124    showLayer('two');
125    hideLayer('one');
126    showNavigateView();
127}
128
129function showLayer(layerName) {
130    if (top.viewFrame.navigateFrame.document.layers) {
131        eval(layerRef + layerName + '.style.display="block"');
132    } else {
133        eval('top.viewFrame.navigateFrame.document.getElementById(' + "'" + layerName + "'" + ').style.display = "block"');
134    }
135}
136
137function hideLayer(layerName) {
138    if (top.viewFrame.navigateFrame.document.layers) {
139        eval(layerRef + layerName + '.style.display="none"');
140    } else {
141        eval('top.viewFrame.navigateFrame.document.getElementById(' + "'" + layerName + "'" + ').style.display = "none"');
142    }
143}
144
145function initnavigate() {
146    if (top.viewFrame.navigateFrame.document.layers) {
147        layerRef = "top.viewFrame.navigateFrame.document.layers.";
148    }
149    if (top.viewFrame.navigateFrame.document.images) {
150    }
151}
152
153function updateTabs(imgName) {
154    with (top.viewFrame.navigateFrame) {
155        if (document.images) {
156            for (var i = 0; i < imgArray.length; i++) {
157                if (imgArray[i][0] == imgName) {
158                    document.all(imgArray[i][0]).src = imgArray[i][1];
159                } else {
160                    document.all(imgArray[i][0]).src = imgArray[i][2];
161                }
162            }
163        }
164    }
165
166}
167
168
169/**-------------------错误提示使用的函数-----------------**/
170//聚焦到错误域中
171function errorFocus(errId) {
172    top.mainFrame.document.all(errId).focus();
173}
174
175//填充错误信息到错误提示面板中
176function fillError() {
177    var tdiv = top.viewFrame.navigateFrame.document.getElementById('error_id');
178    //为解决机构管理(aaf)中的js错误,在2006年3月31日被迫在此进行修改
179    //原来代码为:tdiv.innerHTML = top.mainFrame.document.all("__errorInfo").innerHTML;
180    //wangpu
181    tdiv.innerHTML = document.all("__errorInfo").innerHTML;
182}
183
184//填充导航列表到导航面板中
185function fillNavList() {
186    var tdiv = top.viewFrame.navigateFrame.document.getElementById('nav_id');
187    tdiv.innerHTML = top.mainFrame.document.all("__nav_id").innerHTML;
188}
189
190//填充导航列表,并显示导航列表
191function fillNavAndShow() {
192    //填充导航栏导航内容
193    fillNavList();
194    //显示导航栏
195    showOne();
196    //设置导航栏状态为隐藏状态
197    top.headFrame.isShowNav.value = "true";
198}
199
200//清空导航栏列表,并隐藏
201function clearNavList() {
202    var tdiv = top.viewFrame.navigateFrame.document.getElementById('nav_id');
203    tdiv.innerHTML = "";
204    //设置导航栏状态为隐藏状态
205    top.headFrame.isShowNav.value = "false";
206    //隐藏导航栏
207    hideNavigateView();
208}
209
210
211//从错误提示面板中清空错误信息,并显示导航面板
212function clearError() {
213    var tdiv = top.viewFrame.navigateFrame.document.getElementById('error_id');
214    tdiv.innerHTML = "";
215    if (top.headFrame.isShowNav.value == "true") {
216        //显示导航面板
217        showOne();
218    } else {//隐藏导航栏
219        hideNavigateView();
220    }
221}
222
223function fillJsErrorAndShow(errs) {
224    var tdiv = top.viewFrame.navigateFrame.document.getElementById('error_id');
225    var strHtml = "<TABLE cellSpacing=0 cellPadding=0 width='100%' align=center border=0>";
226    for (var i = 0; i < errs.length; i++) {
227        strHtml += "<TR>";
228        strHtml += "<TD><IMG src='" + rootpath + "/frame/default/images/navigate/error_light.gif'></TD>";
229        strHtml += "<TD class='TD_guide_line_test'><A href=\"javascript:errorFocus('" + errs[i][0] + "');\">" + errs[i][1] + "</A></TD>";
230        strHtml += "</TR>";
231    }
232    strHtml += "</TABLE>";
233    tdiv.innerHTML = strHtml;
234    showTwo();
235    window.attachEvent("onunload", clearError);
236}
237
238//显示等待页面
239function _showWait() {
240    var win = top.headFrame;
241    if (win == null)return;
242    if (win._wait != null)return;
243    win._wait = win.showModelessDialog(rootpath + "/page/frame/Loading.jsp", window, "dialogTop:550px;dialogLeft:750px;dialogHeight: 100px; dialogWidth: 200px; center: yes; help: no; scroll: no; status: no;");
244    ;
245}
246//隐藏等待页面
247function _hiddenWait() {
248    var win = top.headFrame;
249    if (win == null)return;
250    if (win._wait != null) {
251        if (!win._wait.closed)win._wait.close();
252        win._wait = null;
253    }
254}
255//先清,后添事件,防止添加重复事件
256//清事件
257//window.detachEvent("onload",_hiddenWait);
258//window.detachEvent("onunload",_showWait);
259////添加事件
260//window.attachEvent("onload",_hiddenWait);
261//window.attachEvent("onunload",_showWait);
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Puppeteer on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)